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, Base::UNICODE_CONTROL_CHARS
Instance Attribute Summary
Attributes inherited from Base
#backtrace_cleaner, #escape_control_chars, #log, #log_application, #log_environment, #log_exception_details, #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.
-
#exception_details ⇒ Object
The detail Ruby adds to the exception's message, such as did_you_mean suggestions.
-
#file_name_and_line ⇒ Object
Ruby file name and line number that logged the message, followed by the method when the entry has a call site (see SemanticLogger.call_site_level), such as "order.rb:42 Order#submit".
-
#level ⇒ Object
Log level.
-
#message ⇒ Object
Log message.
-
#method_name ⇒ Object
The method that logged the message, such as "Order#submit", when the entry has a call site.
-
#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, shortened before it is escaped, so that an escape is never cut in two.
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
106 107 108 109 110 111 |
# File 'lib/semantic_logger/formatters/default.rb', line 106 def call(log, logger) self.log = log self.logger = logger [time, level, process_info, , , duration, name, , payload, exception].compact.join(" ") end |
#duration ⇒ Object
Duration
67 68 69 |
# File 'lib/semantic_logger/formatters/default.rb', line 67 def duration "(#{log.duration_human})" if log.duration end |
#exception ⇒ Object
Exception
90 91 92 93 94 95 |
# File 'lib/semantic_logger/formatters/default.rb', line 90 def exception return unless log.exception = escape_control_characters(Utils.(log.exception)) "-- Exception: #{Utils.exception_name(log.exception)}: #{}#{exception_detail_lines}" end |
#exception_details ⇒ Object
The detail Ruby adds to the exception's message, such as did_you_mean suggestions.
See Base#initialize for the log_exception_details option.
99 100 101 |
# File 'lib/semantic_logger/formatters/default.rb', line 99 def exception_details escape_control_characters(exception_details_for(log.exception)) if log.exception end |
#file_name_and_line ⇒ Object
Ruby file name and line number that logged the message, followed by the method when the entry has a call site (see SemanticLogger.call_site_level), such as "order.rb:42 Order#submit".
The file name is escaped like the other fields, since it comes from the first line of the backtrace, which a log call can supply from untrusted data.
24 25 26 27 28 29 30 |
# File 'lib/semantic_logger/formatters/default.rb', line 24 def file_name_and_line file, line = log.file_name_and_line(true) return unless file label = method_name label ? "#{escape_control_characters(file)}:#{line} #{label}" : "#{escape_control_characters(file)}:#{line}" 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
77 78 79 |
# File 'lib/semantic_logger/formatters/default.rb', line 77 def "-- #{escape_control_characters(log.)}" if log. end |
#method_name ⇒ Object
The method that logged the message, such as "Order#submit", when the entry has a call site. Escaped like the file name, which it comes from.
34 35 36 |
# File 'lib/semantic_logger/formatters/default.rb', line 34 def method_name escape_control_characters(log.call_site&.label) end |
#name ⇒ Object
Class / app name
72 73 74 |
# File 'lib/semantic_logger/formatters/default.rb', line 72 def name escape_control_characters(log.name) end |
#named_tags ⇒ Object
Named Tags
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/semantic_logger/formatters/default.rb', line 55 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
82 83 84 85 86 87 |
# File 'lib/semantic_logger/formatters/default.rb', line 82 def payload pl = log.payload_to_s return unless pl "-- #{escape_control_characters(pl)}" end |
#process_info ⇒ Object
Returns [String] the available process info Example:
[18934:thread_name test_logging.rb:51]
41 42 43 44 45 |
# File 'lib/semantic_logger/formatters/default.rb', line 41 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
48 49 50 51 52 |
# File 'lib/semantic_logger/formatters/default.rb', line 48 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, shortened before it is escaped, so that an escape is never cut in two.
15 16 17 |
# File 'lib/semantic_logger/formatters/default.rb', line 15 def thread_name escape_control_characters(shortened_thread_name) end |