Class: BBK::Utils::LogFormatter
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- BBK::Utils::LogFormatter
- Defined in:
- lib/bbk/utils/log_formatter.rb
Constant Summary collapse
- FORMAT =
"%5s [%sUTC #%d] (%s)[%s]: %s\n"
Instance Method Summary collapse
- #call(severity, time, progname, msg) ⇒ Object
-
#initialize(tags: []) ⇒ LogFormatter
constructor
A new instance of LogFormatter.
- #thread_id ⇒ Object
- #thread_name_from_main ⇒ Object
Constructor Details
#initialize(tags: []) ⇒ LogFormatter
Returns a new instance of LogFormatter.
11 12 13 14 |
# File 'lib/bbk/utils/log_formatter.rb', line 11 def initialize(tags: []) super() @tags = end |
Instance Method Details
#call(severity, time, progname, msg) ⇒ Object
16 17 18 19 20 |
# File 'lib/bbk/utils/log_formatter.rb', line 16 def call(severity, time, progname, msg) line = msg2str(msg).gsub("\n", '\\n') line = "#{}#{line}" format(FORMAT, severity, format_datetime(time.utc), Process.pid, progname, thread_id, line) end |
#thread_id ⇒ Object
22 23 24 25 26 27 |
# File 'lib/bbk/utils/log_formatter.rb', line 22 def thread_id [ Thread.current.object_id.to_s, Thread.current.name || thread_name_from_main ].compact.join('@') end |
#thread_name_from_main ⇒ Object
29 30 31 32 33 |
# File 'lib/bbk/utils/log_formatter.rb', line 29 def thread_name_from_main if Thread.main.name Thread.current[:bbk_thread_id] ||= "#{Thread.main.name}-#{Thread.current.object_id}" end end |