Class: SemanticLogger::Appender::Base
- Defined in:
- lib/semantic_logger/appender/base.rb
Instance Attribute Summary collapse
-
#formatter ⇒ Object
Returns the value of attribute formatter.
Attributes inherited from Base
Class Method Summary collapse
-
.colorized_formatter ⇒ Object
Optional log formatter to colorize log output To use this formatter SemanticLogger.add_appender($stdout, nil, &SemanticLogger::Logger.colorized_formatter).
Instance Method Summary collapse
-
#default_formatter ⇒ Object
Default log formatter Replace this formatter by supplying a Block to the initializer Generates logs of the form: 2011-07-19 14:36:15.660 D [1149:ScriptThreadProcess] Rails – Hello World.
Methods inherited from Base
default_level, default_level=, #payload, #pop_tags, #push_tags, #tagged, #tags, #with_payload
Instance Attribute Details
#formatter ⇒ Object
Returns the value of attribute formatter.
27 28 29 |
# File 'lib/semantic_logger/appender/base.rb', line 27 def formatter @formatter end |
Class Method Details
.colorized_formatter ⇒ Object
Optional log formatter to colorize log output To use this formatter
SemanticLogger.add_appender($stdout, nil, &SemanticLogger::Logger.colorized_formatter)
2011-07-19 14:36:15.660 D [1149:ScriptThreadProcess] Rails -- Hello World
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/semantic_logger/appender/base.rb', line 52 def self.colorized_formatter Proc.new do |log| colors = SemanticLogger::Appender::AnsiColors = log..collect { |tag| "[#{colors::CYAN}#{tag}#{colors::CLEAR}]" }.join(' ') + ' ' if log. && (log..size > 0) = log..to_s.dup << " -- " << log.payload.inspect if log.payload << " -- Exception: " << "#{colors::BOLD}#{log.exception.class}: #{log.exception.message}#{colors::CLEAR}\n#{(log.exception.backtrace || []).join("\n")}" if log.exception duration_str = log.duration ? "(#{colors::BOLD}#{'%.1f' % log.duration}ms#{colors::CLEAR}) " : '' level_color = case log.level when :trace colors::MAGENTA when :debug colors::GREEN when :info colors::CYAN when :warn colors::BOLD when :error, :fatal colors::RED end "#{SemanticLogger::Appender::Base.formatted_time(log.time)} #{level_color}#{colors::BOLD}#{log.level.to_s[0..0].upcase}#{colors::CLEAR} [#{$$}:#{'%.30s' % log.thread_name}] #{tags}#{duration_str}#{level_color}#{log.name}#{colors::CLEAR} -- #{message}" end end |
Instance Method Details
#default_formatter ⇒ Object
Default log formatter
Replace this formatter by a Block to the initializer
Generates logs of the form:
2011-07-19 14:36:15.660 D [1149:ScriptThreadProcess] Rails -- Hello World
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/semantic_logger/appender/base.rb', line 33 def default_formatter Proc.new do |log| = log..collect { |tag| "[#{tag}]" }.join(" ") + " " if log. && (log..size > 0) = log..to_s.dup << " -- " << log.payload.inspect if log.payload << " -- Exception: " << "#{log.exception.class}: #{log.exception.message}\n#{(log.exception.backtrace || []).join("\n")}" if log.exception duration_str = log.duration ? "(#{'%.1f' % log.duration}ms) " : '' "#{SemanticLogger::Appender::Base.formatted_time(log.time)} #{log.level.to_s[0..0].upcase} [#{$$}:#{'%.50s' % log.thread_name}] #{tags}#{duration_str}#{log.name} -- #{message}" end end |