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

Modules: Appenders, Symbols

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.appendersObject

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(message, level: :info, indent: 0, heading: false, title: false)
  loggers.each do |log|
    message = case message
    when "" || nil
      [ "" ]
    when String
      message.split("\n")
    when Array
      message
    else
      fatal "unknown message type: #{message.class}"
    end

    message = [ "", "" ] + message if title
    message = [ "" ] + message if heading

    if title
      prefix = "  " * 1
    else
      prefix = "  " * indent
    end

    message.each { |line| log.send(level, prefix + line) }
  end
end

.loggersObject



19
20
21
# File 'lib/gclouder/logging.rb', line 19

def self.loggers
  @loggers ||= setup
end

.reportObject



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

.setupObject



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(message, indent: 3, heading: false)
  @@add += 1
  resource_state("#{Symbols.plus} #{message}", 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(message, indent: 3, heading: false)
  @@bad += 1
  resource_state("#{Symbols.x} #{message}", 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(message, indent: 3, heading: false)
  @@change += 1
  resource_state("#{Symbols.o} #{message}", indent: indent, heading: heading)
end

#debug(message = "") ⇒ Object



88
89
90
# File 'lib/gclouder/logging.rb', line 88

def debug(message = "")
  Logging.log message, level: :debug
end

#error(message = "", heading: false) ⇒ Object



100
101
102
# File 'lib/gclouder/logging.rb', line 100

def error(message = "", heading: false)
  Logging.log message, 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(message = "", status: 1, heading: false)
  Logging.log "\n#{message}", 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(message, indent: 3, heading: false)
  @@good += 1
  resource_state("#{Symbols.tick} #{message}", 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(message = "", indent: 0, heading: false, title: false)
  Logging.log message, 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(message, indent: 3, heading: false)
  @@remove += 1
  resource_state("#{Symbols.minus} #{message}", 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(message, indent: 0, heading: false, level: :info)
  Logging.log "#{'  ' * indent}#{message}", level: level, heading: heading
end

#warn(message = "", heading: false) ⇒ Object



96
97
98
# File 'lib/gclouder/logging.rb', line 96

def warn(message = "", heading: false)
  Logging.log message, level: :warn, heading: heading
end

#warning(message, indent: 3, heading: false) ⇒ Object



138
139
140
141
# File 'lib/gclouder/logging.rb', line 138

def warning(message, indent: 3, heading: false)
  @@warning += 1
  resource_state("#{Symbols.bang} #{message}", indent: indent, heading: heading)
end