Module: Zold::Log

Defined in:
lib/zold/log.rb

Overview

Logging facilities.

There are a few logging classes, which can be used depending on what you want a user to see. There are three logging levels: INFO, ERROR, and DEBUG. In “quiet” mode the user won’t see anything. This logging mode is used only for testing, when we don’t want to see absolutely anything in the console. In order to turn off logging entirely, see how we configure it in test__helper.rb

The default “regular” logging mode is what a user gets when he/she runs the gem in commmand line without any specific flags. In that case, the user will see only INFO and ERROR messages.

In a “verbose” mode the user will see everything, including DEBUG messages. The user turns this mode by using –verbose command line argument.

Constant Summary collapse

COMPACT =

Compact formatter

proc do |severity, _time, _target, msg|
  prefix = ''
  case severity
  when 'ERROR', 'FATAL'
    prefix = 'E: '
  when 'DEBUG'
    prefix = 'D: '
  end
  colored(prefix, severity) + msg.to_s.rstrip.gsub(/\n/, "\n" + (' ' * prefix.length)) + "\n"
end
SHORT =

Short formatter

proc do |_severity, _time, _target, msg|
  msg.to_s.rstrip + "\n"
end
FULL =

Full formatter

proc do |severity, time, _target, msg|
  format(
    "%<time>s %<severity>5s %<msg>s\n",
    time: time.utc.iso8601,
    severity: colored(severity, severity),
    msg: msg.to_s.rstrip
  )
end
NULL =

No logging at all

Logger.new(STDOUT)
VERBOSE =

Everything, including debug

Logger.new(STDOUT)
REGULAR =

Info and errors, no debug info

Logger.new(STDOUT)
ERRORS =

Errors only

Logger.new(STDOUT)

Class Method Summary collapse

Class Method Details

.colored(text, severity) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/zold/log.rb', line 48

def self.colored(text, severity)
  case severity
  when 'ERROR', 'FATAL'
    return Rainbow(text).red
  when 'DEBUG'
    return Rainbow(text).yellow
  end
  text
end