Class: ThreadFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/common/thread_formatter.rb

Constant Summary collapse

FORMAT =
"%s, [%s#%d] [%s] %5s -- %s: %s\n".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeThreadFormatter

Returns a new instance of ThreadFormatter.



14
15
16
# File 'lib/common/thread_formatter.rb', line 14

def initialize
  @datetime_format = nil
end

Instance Attribute Details

#datetime_formatObject

Returns the value of attribute datetime_format.



12
13
14
# File 'lib/common/thread_formatter.rb', line 12

def datetime_format
  @datetime_format
end

Class Method Details

.layoutObject

get pattern layout for Logging::Logger



5
6
7
8
9
10
# File 'lib/common/thread_formatter.rb', line 5

def self.layout
  Logging.layouts.pattern(
    pattern: "%.1l, [%d #%p] [%T] %5l -- %c: %m\n",
    date_pattern: '%Y-%m-%dT%H:%M:%S.%s',
  )
end

Instance Method Details

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



18
19
20
21
# File 'lib/common/thread_formatter.rb', line 18

def call(severity, time, progname, msg)
  thread_name = Thread.current[:name] || "0x#{Thread.current.object_id.to_s(16)}"
  format(FORMAT, severity[0..0], format_datetime(time), $$, thread_name, severity, progname, msg2str(msg))
end