lib/pushyd/formatter.rb in pushyd-0.5.1 vs lib/pushyd/formatter.rb in pushyd-0.5.2

- old
+ new

@@ -1,26 +1,25 @@ module PushyDaemon class Formatter - def self.call severity, datetime, progname, messages + def self.call severity, datetime, progname, payload # Build common values timestamp = datetime.strftime(LOG_FORMAT_TIME) + # Build header + header = sprintf LOG_FORMAT_HEADER, + timestamp, + Process.pid, + severity, + progname + # 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 + return payload.map do |line| + "#{header}#{trimmed(line)}\n" + end.join if payload.is_a?(Array) - 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 + # Otherwise, just prefix the only line + return "#{header}#{trimmed(payload)}\n" end protected def self.trimmed line