Module: Logger

Defined in:
lib/logger.rb

Overview

The logger is using colorizing-functionality from Thor’s shell

Defined Under Namespace

Classes: LogLevel

Constant Summary collapse

LEVEL =
{
  :debug  => LogLevel.new(0,  "DEBUG ", :white),
  :info   => LogLevel.new(1,  "INFO  ", :blue),
  :warn   => LogLevel.new(2,  "WARN  ", :yellow),
  :error  => LogLevel.new(3,  "ERROR ", :red),
  :system => LogLevel.new(10, "",       :black)
}

Class Method Summary collapse

Class Method Details

.method_missing(name, *args) ⇒ Object

Raises:

  • (NoMethodError)


26
27
28
29
30
31
# File 'lib/logger.rb', line 26

def self.method_missing(name, *args)
  level = LEVEL[name.to_sym]    
  raise NoMethodError.new(name.to_s) if level.nil?
  
  log(level, args)
end

.setup(args = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/logger.rb', line 16

def self.setup(args = {})

  @@shell = Thor::Base.shell.new
  @@logfile = args[:logfile] 
  @@level   = LEVEL[args[:level] || :info]
  
  # write start sequence
  log LEVEL[:info], ["\n\n== #{Time.now} #{'='*50}"]
end