Class: Worochi::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/worochi/log.rb

Overview

Implements colored log messages.

Constant Summary collapse

SEVERITY_COLOR =

Maps severity level to color code for logging.

{
  'DEBUG' => 37,
  'INFO' => 32,
  'WARN' => 33,
  'ERROR' => 31,
  'FATAL' => 31
}

Class Method Summary collapse

Class Method Details

.debug(message) ⇒ Object

Prints DEBUG messages


26
27
28
# File 'lib/worochi/log.rb', line 26

def debug(message)
  @logger.debug message unless Worochi::Config.silent?
end

.error(message) ⇒ Object

Prints ERROR messages


41
42
43
# File 'lib/worochi/log.rb', line 41

def error(message)
  @logger.error message unless Worochi::Config.silent?
end

.info(message) ⇒ Object

Prints INFO messages


36
37
38
# File 'lib/worochi/log.rb', line 36

def info(message)
  @logger.info message unless Worochi::Config.silent?
end

.init(logdev = nil) ⇒ Object

Initializes the logging system.

Parameters:

  • logdev (IO) (defaults to: nil)

    target device to log to


18
19
20
21
22
23
# File 'lib/worochi/log.rb', line 18

def init(logdev=nil)
  @logger = Logger.new(logdev || Config.logdev)
  @logger.formatter = proc do |severity, datetime, progname, msg|
    "[\033[#{SEVERITY_COLOR[severity]}m#{severity}\033[0m]: #{msg}\n"
  end
end

.warn(message) ⇒ Object

Prints WARN messages


31
32
33
# File 'lib/worochi/log.rb', line 31

def warn(message)
  @logger.warn message unless Worochi::Config.silent?
end