Class: Nucleus::Logging::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/nucleus/core/common/logging/request_log_formatter.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFormatter

Returns a new instance of Formatter.



10
11
12
# File 'lib/nucleus/core/common/logging/request_log_formatter.rb', line 10

def initialize
  @datetime_format = nil
end

Instance Attribute Details

#datetime_formatObject

Returns the value of attribute datetime_format.



8
9
10
# File 'lib/nucleus/core/common/logging/request_log_formatter.rb', line 8

def datetime_format
  @datetime_format
end

Instance Method Details

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



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/nucleus/core/common/logging/request_log_formatter.rb', line 14

def call(severity, time, progname, msg)
  if Thread.current[:nucleus_request_id].nil?
    # if there is no request id, then fill up the space
    request_part = "[#{'*' * 36}]"
  else
    request_part = "[#{Thread.current[:nucleus_request_id]}]"
  end

  format(FORMAT, severity[0..0], request_part, format_datetime(time),
         $PID, severity, progname, msg2str(msg))
end