class LogSanity::Formatter

Attributes

string_formatter[W]

Public Instance Methods

call(severity, timestamp, progname, msg) click to toggle source

tags are ignored when rendering as json however, tags are prepended when rendering with string_formatter

# File lib/log_sanity/formatter.rb, line 16
def call(severity, timestamp, progname, msg)
  if msg.is_a? Hash
    msg.reverse_merge!('at' => timestamp) unless msg.key?('at')
  elsif msg.is_a? String
    if string_formatter
      msg = "#{tags_text}#{msg}" if current_tags.any?
      return string_formatter.call(severity, timestamp, progname, msg)
    else
      msg = {'at' => timestamp, 'message' => msg}
    end
  else
    msg = {'at' => timestamp, 'object' => msg.inspect}
  end
  if msg['at'].is_a? Float
    monot = Process.clock_gettime(Process::CLOCK_MONOTONIC)
    msg['at'] = Time.now - (monot - msg['at'])
  end
  msg['at'] = msg['at'].utc
  "#{msg.to_json}\n"
end
string_formatter() click to toggle source
# File lib/log_sanity/formatter.rb, line 39
def string_formatter
  return @string_formatter if defined?(@string_formatter)
  @string_formatter ||= ActiveSupport::Logger::SimpleFormatter.new
end