module GClouder::Logging

Attributes

appenders[RW]

Public Class Methods

included(klass) click to toggle source
# 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) click to toggle source
# 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
loggers() click to toggle source
# File lib/gclouder/logging.rb, line 19
def self.loggers
  @loggers ||= setup
end
report() click to toggle source
# 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() click to toggle source
# 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

Public Instance Methods

add(message, indent: 3, heading: false) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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 = "") click to toggle source
# File lib/gclouder/logging.rb, line 88
def debug(message = "")
  Logging.log message, level: :debug
end
error(message = "", heading: false) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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