Class: LittleLogFriend::Formatter
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- LittleLogFriend::Formatter
- Defined in:
- lib/little_log_friend/formatter.rb
Constant Summary collapse
- Format =
"%s [%5s] %d %s: %s"
- @@colorize =
false
- @@colors =
{ 'DEBUG' => "\e[1;32;1m", # green 'INFO' => "\e[0;1m", # white 'WARN' => "\e[1;33;1m", # yello 'ERROR' => "\e[1;31;1m", # red 'FATAL' => "\e[1;35;1m", # punk, yes PUNK! 'UNKNOWN' => "\e[0;1m", # white 'DEFAULT' => "\e[0m" # NONE }
Class Method Summary collapse
Instance Method Summary collapse
-
#call(severity, time, progname, msg) ⇒ Object
This method is invoked when a log event occurs.
-
#initialize ⇒ Formatter
constructor
A new instance of Formatter.
- #number_to_severity(n) ⇒ Object
Constructor Details
#initialize ⇒ Formatter
Returns a new instance of Formatter.
19 20 21 22 |
# File 'lib/little_log_friend/formatter.rb', line 19 def initialize super @datetime_format = "%Y-%m-%d %H:%M:%S" end |
Class Method Details
.colorize!(options = {}) ⇒ Object
24 25 26 27 |
# File 'lib/little_log_friend/formatter.rb', line 24 def self.colorize!( = {} ) @@colorize = true .each { |key, value| @@colors[key.to_s.upcase] = value } end |
Instance Method Details
#call(severity, time, progname, msg) ⇒ Object
This method is invoked when a log event occurs
30 31 32 33 34 |
# File 'lib/little_log_friend/formatter.rb', line 30 def call ( severity, time, progname, msg ) msg = Format % [format_datetime(time), severity, $$, progname, msg2str(msg)] msg = @@colors[severity] + msg + @@colors['DEFAULT'] if @@colorize msg << "\n" end |
#number_to_severity(n) ⇒ Object
36 37 38 39 |
# File 'lib/little_log_friend/formatter.rb', line 36 def number_to_severity ( n ) severities = [:debug, :info, :warn, :error, :fatal, :unknown] severities[n] end |