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
86 87 88 89 90 91 |
# File 'lib/semantic_logger/formatters/default.rb', line 86 def call(log, logger) self.log = log self.logger = logger [time, level, process_info, , , duration, name, , payload, exception].compact.join(" ") end |
#duration ⇒ Object
Duration
53 54 55 |
# File 'lib/semantic_logger/formatters/default.rb', line 53 def duration "(#{log.duration_human})" if log.duration end |
#exception ⇒ Object
Exception
76 77 78 79 80 81 |
# File 'lib/semantic_logger/formatters/default.rb', line 76 def exception return unless log.exception "-- Exception: #{log.exception.class}: #{escape_control_characters(log.exception.)}\n" \ "#{log.backtrace_to_s}" 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
63 64 65 |
# File 'lib/semantic_logger/formatters/default.rb', line 63 def "-- #{escape_control_characters(log.)}" if log. end |
#name ⇒ Object
Class / app name
58 59 60 |
# File 'lib/semantic_logger/formatters/default.rb', line 58 def name log.name end |
#named_tags ⇒ Object
Named Tags
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/semantic_logger/formatters/default.rb', line 41 def = log. return if .nil? || .empty? list = [] .each_pair do |name, value| list << "#{escape_control_characters(name)}: #{escape_control_characters(value)}" end "{#{list.join(', ')}}" end |
#payload ⇒ Object
Payload
68 69 70 71 72 73 |
# File 'lib/semantic_logger/formatters/default.rb', line 68 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 |