Class: PushyDaemon::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/pushyd/formatter.rb

Class Method Summary collapse

Class Method Details

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



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

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

  # If we have a bunch of lines, prefix them and send them together
  if messages.is_a? Array
    messages.map do |line|
      sprintf LOG_FORMAT_ARRAY, timestamp, severity, progname, trimmed(line)
    end.join

  elsif messages.is_a? Hash
    messages.map do |key, value|
      sprintf LOG_FORMAT_HASH, timestamp, severity, progname, key, value
    end.join

  else
    sprintf LOG_FORMAT_LINE, timestamp, severity, progname, trimmed(messages)

  end
end