Class: SemanticLogger::Formatters::Default
- Defined in:
- lib/semantic_logger/formatters/default.rb
Overview
Default non-colored text log output
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#log ⇒ Object
Returns the value of attribute log.
-
#logger ⇒ Object
Returns the value of attribute logger.
Attributes inherited from Base
#log_application, #log_host, #precision, #time_format
Instance Method Summary collapse
-
#call(log, logger) ⇒ Object
Default text log format Generates logs of the form: 2011-07-19 14:36:15.660235 D [1149:ScriptThreadProcess] Rails – Hello World.
-
#duration ⇒ Object
Duration.
-
#exception ⇒ Object
Exception.
-
#level ⇒ Object
Log level.
-
#message ⇒ Object
Log message.
-
#name ⇒ Object
Class / app name.
-
#named_tags ⇒ Object
Named Tags.
-
#payload ⇒ Object
Payload.
-
#process_info ⇒ Object
Process info.
-
#tags ⇒ Object
Tags.
Methods inherited from Base
build_time_format, #initialize, #time
Constructor Details
This class inherits a constructor from SemanticLogger::Formatters::Base
Instance Attribute Details
#log ⇒ Object
Returns the value of attribute log.
5 6 7 |
# File 'lib/semantic_logger/formatters/default.rb', line 5 def log @log end |
#logger ⇒ Object
Returns the value of attribute logger.
5 6 7 |
# File 'lib/semantic_logger/formatters/default.rb', line 5 def logger @logger end |
Instance Method Details
#call(log, logger) ⇒ Object
Default text log format
Generates logs of the form:
2011-07-19 14:36:15.660235 D [1149:ScriptThreadProcess] Rails -- Hello World
66 67 68 69 70 71 |
# File 'lib/semantic_logger/formatters/default.rb', line 66 def call(log, logger) self.log = log self.logger = logger [time, level, process_info, , , duration, name, , payload, exception].compact.join(' ') end |
#duration ⇒ Object
Duration
36 37 38 |
# File 'lib/semantic_logger/formatters/default.rb', line 36 def duration "(#{log.duration_human})" if log.duration end |
#exception ⇒ Object
Exception
59 60 61 |
# File 'lib/semantic_logger/formatters/default.rb', line 59 def exception "-- Exception: #{log.exception.class}: #{log.exception.}\n#{log.backtrace_to_s}" if log.exception end |
#level ⇒ Object
Log level
11 12 13 |
# File 'lib/semantic_logger/formatters/default.rb', line 11 def level log.level_to_s end |
#message ⇒ Object
Log message
46 47 48 |
# File 'lib/semantic_logger/formatters/default.rb', line 46 def "-- #{log.}" if log. end |
#name ⇒ Object
Class / app name
41 42 43 |
# File 'lib/semantic_logger/formatters/default.rb', line 41 def name log.name end |
#named_tags ⇒ Object
Named Tags
26 27 28 29 30 31 32 33 |
# File 'lib/semantic_logger/formatters/default.rb', line 26 def = log. return if .nil? || .empty? list = [] .each_pair { |name, value| list << "#{name}: #{value}" } "{#{list.join(', ')}}" end |
#payload ⇒ Object
Payload
51 52 53 54 55 56 |
# File 'lib/semantic_logger/formatters/default.rb', line 51 def payload pl = log.payload_to_s return unless pl "-- #{pl}" end |
#process_info ⇒ Object
Process info
16 17 18 |
# File 'lib/semantic_logger/formatters/default.rb', line 16 def process_info "[#{log.process_info}]" end |
#tags ⇒ Object
Tags
21 22 23 |
# File 'lib/semantic_logger/formatters/default.rb', line 21 def "[#{log..join('] [')}]" if log. && !log..empty? end |