Class: BBK::Utils::LogFormatter

Inherits:
Logger::Formatter
  • Object
show all
Defined in:
lib/bbk/utils/log_formatter.rb

Constant Summary collapse

FORMAT =
"%5s [%sUTC #%d] (%s)[%s]: %s\n"

Instance Method Summary collapse

Instance Method Details

#call(severity, time, progname, msg) ⇒ Object



9
10
11
12
# File 'lib/bbk/utils/log_formatter.rb', line 9

def call(severity, time, progname, msg)
  line = msg2str(msg).gsub("\n", '\\n')
  format(FORMAT, severity, format_datetime(time.utc), Process.pid, progname, thread_id, line)
end

#thread_idObject



14
15
16
17
18
19
# File 'lib/bbk/utils/log_formatter.rb', line 14

def thread_id
  [
    Thread.current.object_id.to_s,
    Thread.current.name || thread_name_from_main
  ].compact.join('@')
end

#thread_name_from_mainObject



21
22
23
# File 'lib/bbk/utils/log_formatter.rb', line 21

def thread_name_from_main
  Thread.current[:bbk_thread_id] ||= "#{Thread.main.name}-#{Thread.current.object_id}" if Thread.main.name
end