lib/semantic_logger/formatters/default.rb in semantic_logger-4.6.1 vs lib/semantic_logger/formatters/default.rb in semantic_logger-4.7.0
- old
+ new
@@ -1,22 +1,35 @@
module SemanticLogger
module Formatters
# Default non-colored text log output
class Default < Base
- attr_accessor :log, :logger
-
# Formatting methods, must return nil, or a string
# Nil values are ignored
# Log level
def level
log.level_to_s
end
- # Process info
+ # Name of the thread that logged the message.
+ def thread_name
+ format("%.30s", log.thread_name)
+ end
+
+ # Ruby file name and line number that logged the message.
+ def file_name_and_line
+ file, line = log.file_name_and_line(true)
+ "#{file}:#{line}" if file
+ end
+
+ # Returns [String] the available process info
+ # Example:
+ # [18934:thread_name test_logging.rb:51]
def process_info
- "[#{log.process_info}]"
+ process_id = "#{pid}:" if pid
+ fname = file_name_and_line
+ fname ? "[#{process_id}#{thread_name} #{fname}]" : "[#{process_id}#{thread_name}]"
end
# Tags
def tags
"[#{log.tags.join('] [')}]" if log.tags && !log.tags.empty?
@@ -65,10 +78,10 @@
# 2011-07-19 14:36:15.660235 D [1149:ScriptThreadProcess] Rails -- Hello World
def call(log, logger)
self.log = log
self.logger = logger
- [time, level, process_info, tags, named_tags, duration, name, message, payload, exception].compact.join(' ')
+ [time, level, process_info, tags, named_tags, duration, name, message, payload, exception].compact.join(" ")
end
end
end
end