Class: Shared::LoggerFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/shared/logger_formatter.rb

Class Method Summary collapse

Class Method Details

.call(severity, datetime, progname, payload) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/shared/logger_formatter.rb', line 4

def self.call severity, datetime, progname, payload
  # Build common values
  timestamp = datetime.strftime(LOG_HEADER_TIME)

  # Build header
  header = sprintf LOG_HEADER_FORMAT,
    timestamp,
    Process.pid,
    severity,
    progname

  # If we have a bunch of lines, prefix them and send them together
  return payload.map do |line|
    "#{header}#{trimmed(line)}\n"
  end.join if payload.is_a?(Array)

  # Otherwise, just prefix the only line
  return "#{header}#{trimmed(payload)}\n"
end