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
Attributes inherited from Base
#log, #log_application, #log_environment, #log_host, #logger, #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.
-
#file_name_and_line ⇒ Object
Ruby file name and line number that logged the message.
-
#level ⇒ Object
Log level.
-
#message ⇒ Object
Log message.
-
#name ⇒ Object
Class / app name.
-
#named_tags ⇒ Object
Named Tags.
-
#payload ⇒ Object
Payload.
-
#process_info ⇒ Object
Returns [String] the available process info Example: [18934:thread_name test_logging.rb:51].
-
#tags ⇒ Object
Tags.
-
#thread_name ⇒ Object
Name of the thread that logged the message.
Methods inherited from Base
build_time_format, #initialize, #pid, #time
Constructor Details
This class inherits a constructor from SemanticLogger::Formatters::Base
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
79 80 81 82 83 84 |
# File 'lib/semantic_logger/formatters/default.rb', line 79 def call(log, logger) self.log = log self.logger = logger [time, level, process_info, , , duration, name, , payload, exception].compact.join(" ") end |
#duration ⇒ Object
Duration
49 50 51 |
# File 'lib/semantic_logger/formatters/default.rb', line 49 def duration "(#{log.duration_human})" if log.duration end |
#exception ⇒ Object
Exception
72 73 74 |
# File 'lib/semantic_logger/formatters/default.rb', line 72 def exception "-- Exception: #{log.exception.class}: #{log.exception.message}\n#{log.backtrace_to_s}" if log.exception end |
#file_name_and_line ⇒ Object
Ruby file name and line number that logged the message.
19 20 21 22 |
# File 'lib/semantic_logger/formatters/default.rb', line 19 def file_name_and_line file, line = log.file_name_and_line(true) "#{file}:#{line}" if file end |
#level ⇒ Object
Log level
9 10 11 |
# File 'lib/semantic_logger/formatters/default.rb', line 9 def level log.level_to_s end |
#message ⇒ Object
Log message
59 60 61 |
# File 'lib/semantic_logger/formatters/default.rb', line 59 def "-- #{log.message}" if log. end |
#name ⇒ Object
Class / app name
54 55 56 |
# File 'lib/semantic_logger/formatters/default.rb', line 54 def name log.name end |
#named_tags ⇒ Object
Named Tags
39 40 41 42 43 44 45 46 |
# File 'lib/semantic_logger/formatters/default.rb', line 39 def = log. return if .nil? || .empty? list = [] .each_pair { |name, value| list << "#{name}: #{value}" } "{#{list.join(', ')}}" end |
#payload ⇒ Object
Payload
64 65 66 67 68 69 |
# File 'lib/semantic_logger/formatters/default.rb', line 64 def payload pl = log.payload_to_s return unless pl "-- #{pl}" end |
#process_info ⇒ Object
Returns [String] the available process info Example:
[18934:thread_name test_logging.rb:51]
27 28 29 30 31 |
# File 'lib/semantic_logger/formatters/default.rb', line 27 def process_info process_id = "#{pid}:" if pid fname = file_name_and_line fname ? "[#{process_id}#{thread_name} #{fname}]" : "[#{process_id}#{thread_name}]" end |
#tags ⇒ Object
Tags
34 35 36 |
# File 'lib/semantic_logger/formatters/default.rb', line 34 def "[#{log.tags.join('] [')}]" if log. && !log..empty? end |
#thread_name ⇒ Object
Name of the thread that logged the message.
14 15 16 |
# File 'lib/semantic_logger/formatters/default.rb', line 14 def thread_name format("%.30s", log.thread_name) end |