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
Base::CONTROL_CHARS, Base::CONTROL_CHAR_ESCAPES, Base::PRECISION
Instance Attribute Summary
Attributes inherited from Base
#escape_control_chars, #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
81 82 83 84 85 86 |
# File 'lib/semantic_logger/formatters/default.rb', line 81 def call(log, logger) self.log = log self.logger = logger [time, level, process_info, , , duration, name, , payload, exception].compact.join(" ") end |
#duration ⇒ Object
Duration
51 52 53 |
# File 'lib/semantic_logger/formatters/default.rb', line 51 def duration "(#{log.duration_human})" if log.duration end |
#exception ⇒ Object
Exception
74 75 76 |
# File 'lib/semantic_logger/formatters/default.rb', line 74 def exception "-- Exception: #{log.exception.class}: #{escape_control_characters(log.exception.)}\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
61 62 63 |
# File 'lib/semantic_logger/formatters/default.rb', line 61 def "-- #{escape_control_characters(log.)}" if log. end |
#name ⇒ Object
Class / app name
56 57 58 |
# File 'lib/semantic_logger/formatters/default.rb', line 56 def name log.name end |
#named_tags ⇒ Object
Named Tags
41 42 43 44 45 46 47 48 |
# File 'lib/semantic_logger/formatters/default.rb', line 41 def = log. return if .nil? || .empty? list = [] .each_pair { |name, value| list << "#{escape_control_characters(name)}: #{escape_control_characters(value)}" } "{#{list.join(', ')}}" end |
#payload ⇒ Object
Payload
66 67 68 69 70 71 |
# File 'lib/semantic_logger/formatters/default.rb', line 66 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 37 38 |
# File 'lib/semantic_logger/formatters/default.rb', line 34 def return if log..nil? || log..empty? "[#{log..map { |tag| escape_control_characters(tag) }.join('] [')}]" 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 |