Class: StderrLogger::Logger

Inherits:
Logger
  • Object
show all
Includes:
Colored
Defined in:
lib/stderr_logger.rb

Constant Summary collapse

USE_COLOR =
STDERR.tty?
SEVERITY_TO_COLOR =
{
  "INFO"  => {:foreground => :white},
  "DEBUG" => {:foreground => :yellow},
  "ERROR" => {:foreground => :red}
}

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/stderr_logger.rb', line 15

def initialize()
  super(STDERR)
  if USE_COLOR
    self.formatter = proc { |severity, datetime, progname, msg|
      time = datetime.strftime("%b %e %H:%M:%S")
      "#{time} #{File.basename($0)} : #{colorize(msg, SEVERITY_TO_COLOR[severity])}\n"
    }
  else
    self.formatter = proc { |severity, datetime, progname, msg|
      time = datetime.strftime("%b %e %H:%M:%S")
      "#{time} #{File.basename($0)} #{severity} : #{msg}\n"
    }
  end
end