class LogjamAgent::SyslogLikeFormatter

Constants

SEV_LABEL

Public Class Methods

new() click to toggle source
# File lib/logjam_agent/syslog_like_formatter.rb, line 5
def initialize
  @hostname = LogjamAgent.hostname
  @app_name = "rails"
  @newline = ActiveSupport::VERSION::STRING < "4.0" ? "" : "\n"
end

Public Instance Methods

attributes() click to toggle source
# File lib/logjam_agent/syslog_like_formatter.rb, line 15
def attributes
  unless attributes = Thread.current.thread_variable_get(:__logjam_formatter_attributes__)
    attributes = Thread.current.thread_variable_set(:__logjam_formatter_attributes__, [])
  end
  attributes
end
attributes=(attributes) click to toggle source
# File lib/logjam_agent/syslog_like_formatter.rb, line 11
def attributes=(attributes)
  Thread.current.thread_variable_set(:__logjam_formatter_attributes__, attributes)
end
call(severity, timestamp, progname, msg) click to toggle source
# File lib/logjam_agent/syslog_like_formatter.rb, line 40
def call(severity, timestamp, progname, msg)
  "#{format_severity(severity)} #{format_time(timestamp)}#{render_attributes}#{format_host_info(progname)}: #{format_message(msg)}#{@newline}"
end
format_host_info(progname) click to toggle source
# File lib/logjam_agent/syslog_like_formatter.rb, line 45
def format_host_info(progname); ""; end
format_message(msg) click to toggle source
# File lib/logjam_agent/syslog_like_formatter.rb, line 36
def format_message(msg)
  msg.strip
end
format_severity(severity) click to toggle source
# File lib/logjam_agent/syslog_like_formatter.rb, line 24
def format_severity(severity)
  if severity.is_a?(String)
    "%-5s" % severity
  else
    SEV_LABEL[severity] || 'ALIEN'
  end
end
format_time(timestamp) click to toggle source
# File lib/logjam_agent/syslog_like_formatter.rb, line 32
def format_time(timestamp)
  timestamp.strftime("%b %d %H:%M:%S.#{"%06d" % timestamp.usec}")
end
render_attributes() click to toggle source
# File lib/logjam_agent/syslog_like_formatter.rb, line 52
def render_attributes
  attributes.map{|key, value| " #{key}[#{value}]"}.join
end
reset_attributes() click to toggle source
# File lib/logjam_agent/syslog_like_formatter.rb, line 64
def reset_attributes
  self.attributes = []
end
set_attribute(name, value) click to toggle source
# File lib/logjam_agent/syslog_like_formatter.rb, line 56
def set_attribute(name, value)
  if attribute = attributes.detect{|n,v| n == name}
    attribute[1] = value
  else
    attributes << [name, value]
  end
end