Module: GClouder::Logging
- Included in:
- GClouder, Config::Arguments, Config::Defaults, Config::Project, Config::ResourceRepresentations, ConfigSection, GCloud, Mappings::Argument, Mappings::File, Mappings::Property, Mappings::ResourceRepresentation, Resource, Resources::Compute::Addresses, Resources::Compute::BGPVPNs, Resources::Compute::BGPVPNs::BGPVPN, Resources::Compute::BackendBuckets, Resources::Compute::BackendBuckets::Local, Resources::Compute::Disks, Resources::Compute::Disks::Local, Resources::Compute::FirewallRules, Resources::Compute::FirewallRules::Local, Resources::Compute::FirewallRules::Rule, Resources::Compute::ForwardingRules, Resources::Compute::Instances, Resources::Compute::Networks, Resources::Compute::Networks::Local, Resources::Compute::Networks::Subnets, Resources::Compute::Networks::Subnets::Local, Resources::Compute::ProjectInfo::SSHKeys, Resources::Compute::ProjectInfo::SSHKeys::Local, Resources::Compute::Routers, Resources::Compute::Routers::Local, Resources::Compute::TargetHTTPSProxies, Resources::Compute::TargetHTTPSProxies::Local, Resources::Compute::URLMaps, Resources::Compute::URLMaps::Local, Resources::Compute::VPNs, Resources::Compute::VPNs::VPN, Resources::Container::Clusters, Resources::Container::Clusters::Cluster, Resources::Container::NodePools, Resources::Container::NodePools::NodePool, Resources::DNS, Resources::DNS::Records, Resources::Functions::Function, Resources::Functions::Function::Local, Resources::Global, Resources::Logging::Sinks, Resources::Logging::Sinks::Local, Resources::Project, Resources::Project::IAMPolicyBinding, Resources::Project::IAMPolicyBinding::Local, Resources::Project::IAMPolicyBinding::Remote, Resources::Project::Local, Resources::PubSub::Subscriptions, Resources::PubSub::Subscriptions::Local, Resources::PubSub::Topics, Resources::PubSub::Topics::Local, Resources::Region, Resources::RuntimeConfig::Configs, Resources::RuntimeConfig::Configs::Local, Resources::RuntimeConfig::Variables, Resources::RuntimeConfig::Variables::Local, Resources::Storage::Buckets, Resources::Storage::Notifications, Resources::Validate::Global, Resources::Validate::Local, Resources::Validate::Region, Resources::Validate::Remote, Shell
- Defined in:
- lib/gclouder/logging.rb
Defined Under Namespace
Class Attribute Summary collapse
-
.appenders ⇒ Object
Returns the value of attribute appenders.
Class Method Summary collapse
- .included(klass) ⇒ Object
- .log(message, level: :info, indent: 0, heading: false, title: false) ⇒ Object
- .loggers ⇒ Object
- .report ⇒ Object
- .setup ⇒ Object
Instance Method Summary collapse
- #add(message, indent: 3, heading: false) ⇒ Object
- #bad(message, indent: 3, heading: false) ⇒ Object
- #change(message, indent: 3, heading: false) ⇒ Object
- #debug(message = "") ⇒ Object
- #error(message = "", heading: false) ⇒ Object
- #fatal(message = "", status: 1, heading: false) ⇒ Object
- #good(message, indent: 3, heading: false) ⇒ Object
- #info(message = "", indent: 0, heading: false, title: false) ⇒ Object
- #remove(message, indent: 3, heading: false) ⇒ Object
- #resource_state(message, indent: 0, heading: false, level: :info) ⇒ Object
- #warn(message = "", heading: false) ⇒ Object
- #warning(message, indent: 3, heading: false) ⇒ Object
Class Attribute Details
.appenders ⇒ Object
Returns the value of attribute appenders.
9 10 11 |
# File 'lib/gclouder/logging.rb', line 9 def appenders @appenders end |
Class Method Details
.included(klass) ⇒ Object
23 24 25 |
# File 'lib/gclouder/logging.rb', line 23 def self.included(klass) klass.extend Logging end |
.log(message, level: :info, indent: 0, heading: false, title: false) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gclouder/logging.rb', line 35 def self.log(, level: :info, indent: 0, heading: false, title: false) loggers.each do |log| = case when "" || nil [ "" ] when String .split("\n") when Array else fatal "unknown message type: #{.class}" end = [ "", "" ] + if title = [ "" ] + if heading if title prefix = " " * 1 else prefix = " " * indent end .each { |line| log.send(level, prefix + line) } end end |
.loggers ⇒ Object
19 20 21 |
# File 'lib/gclouder/logging.rb', line 19 def self.loggers @loggers ||= setup end |
.report ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/gclouder/logging.rb', line 169 def self.report Logging.log "\n\n [report]" Logging.log " " Logging.log " #{Symbols.tick} - #{@@good}" Logging.log " #{Symbols.bang} - #{@@warning}" Logging.log " #{Symbols.x} - #{@@bad}" Logging.log " " Logging.log " #{Symbols.plus} - #{@@add}" Logging.log " #{Symbols.o} - #{@@change}" Logging.log " #{Symbols.minus} - #{@@remove}" end |
.setup ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/gclouder/logging.rb', line 27 def self.setup appenders.map do |appender| appender[:appender].formatter = appender[:format] appender[:appender].level = Logger::DEBUG appender[:appender] end end |
Instance Method Details
#add(message, indent: 3, heading: false) ⇒ Object
123 124 125 126 |
# File 'lib/gclouder/logging.rb', line 123 def add(, indent: 3, heading: false) @@add += 1 resource_state("#{Symbols.plus} #{}", indent: indent, heading: heading) end |
#bad(message, indent: 3, heading: false) ⇒ Object
118 119 120 121 |
# File 'lib/gclouder/logging.rb', line 118 def bad(, indent: 3, heading: false) @@bad += 1 resource_state("#{Symbols.x} #{}", indent: indent, heading: heading) end |
#change(message, indent: 3, heading: false) ⇒ Object
128 129 130 131 |
# File 'lib/gclouder/logging.rb', line 128 def change(, indent: 3, heading: false) @@change += 1 resource_state("#{Symbols.o} #{}", indent: indent, heading: heading) end |
#debug(message = "") ⇒ Object
88 89 90 |
# File 'lib/gclouder/logging.rb', line 88 def debug( = "") Logging.log , level: :debug end |
#error(message = "", heading: false) ⇒ Object
100 101 102 |
# File 'lib/gclouder/logging.rb', line 100 def error( = "", heading: false) Logging.log , level: :error, heading: heading end |
#fatal(message = "", status: 1, heading: false) ⇒ Object
104 105 106 107 |
# File 'lib/gclouder/logging.rb', line 104 def fatal( = "", status: 1, heading: false) Logging.log "\n#{}", level: :fatal, heading: heading exit status end |
#good(message, indent: 3, heading: false) ⇒ Object
113 114 115 116 |
# File 'lib/gclouder/logging.rb', line 113 def good(, indent: 3, heading: false) @@good += 1 resource_state("#{Symbols.tick} #{}", indent: indent, heading: heading) end |
#info(message = "", indent: 0, heading: false, title: false) ⇒ Object
92 93 94 |
# File 'lib/gclouder/logging.rb', line 92 def info( = "", indent: 0, heading: false, title: false) Logging.log , level: :info, indent: indent, heading: heading, title: title end |
#remove(message, indent: 3, heading: false) ⇒ Object
133 134 135 136 |
# File 'lib/gclouder/logging.rb', line 133 def remove(, indent: 3, heading: false) @@remove += 1 resource_state("#{Symbols.minus} #{}", indent: indent, heading: heading) end |
#resource_state(message, indent: 0, heading: false, level: :info) ⇒ Object
109 110 111 |
# File 'lib/gclouder/logging.rb', line 109 def resource_state(, indent: 0, heading: false, level: :info) Logging.log "#{' ' * indent}#{}", level: level, heading: heading end |