Class: Yummi::Formatter::LogFormatter
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- Yummi::Formatter::LogFormatter
- Includes:
- BlockHandler
- Defined in:
- lib/yummi/logger.rb
Overview
A colorful log formatter
Instance Attribute Summary collapse
-
#colors ⇒ Object
Colors for each severity:.
Instance Method Summary collapse
- #call(severity, time, program_name, message) ⇒ Object
-
#initialize(colors = {}, &block) ⇒ LogFormatter
constructor
Creates a new formatter with the colors (assuming Linux default terminal colors):.
-
#output(severity, time, program_name, message) ⇒ Object
Formats the message, override this method instead of #call.
- #super_call ⇒ Object
Methods included from BlockHandler
Constructor Details
#initialize(colors = {}, &block) ⇒ LogFormatter
Creates a new formatter with the colors (assuming Linux default terminal colors):
-
DEBUG
: blue -
INFO
: white -
WARN
: yellow -
ERROR
: red -
FATAL
: red (intense) -
ANY
: black (intense)
If a block is passed, it will be used to format the message. The block can use the following variables: severity, time, program_name and message.
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/yummi/logger.rb', line 59 def initialize colors = {}, &block @colors = { :debug => :blue, :info => :white, :warn => :yellow, :error => :red, :fatal => :intense_red, :any => :intense_black }.merge! colors @format_block = block end |
Instance Attribute Details
#colors ⇒ Object
Colors for each severity:
-
:debug
-
:info
-
:warn
-
:error
-
:fatal
-
:any
44 45 46 |
# File 'lib/yummi/logger.rb', line 44 def colors @colors end |
Instance Method Details
#call(severity, time, program_name, message) ⇒ Object
73 74 75 76 |
# File 'lib/yummi/logger.rb', line 73 def call(severity, time, program_name, ) color = @colors[severity.downcase.to_sym] Yummi::colorize output(severity, time, program_name, ), color end |
#output(severity, time, program_name, message) ⇒ Object
Formats the message, override this method instead of #call
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/yummi/logger.rb', line 79 def output severity, time, program_name, if @format_block context = { :severity => severity, :time => time, :program_name => program_name, :message => } block_call(context, &@format_block) << $/ else super_call severity, time, program_name, end end |
#super_call ⇒ Object
71 |
# File 'lib/yummi/logger.rb', line 71 alias_method :super_call, :call |