Sha256: 8d10b32b93c2a3d057dc99bb8699ff6d02c96b15c66491ab53819ec43f6d4dd9
Contents?: true
Size: 961 Bytes
Versions: 2
Compression:
Stored size: 961 Bytes
Contents
require 'socket' require 'logger' module LogjamAgent class SyslogLikeFormatter def initialize @hostname = Socket.gethostname.split('.').first @app_name = "rails" end attr_accessor :extra_attributes SEV_LABEL = Logger::SEV_LABEL.map{|sev| "%-5s" % sev} def format_severity(severity) SEV_LABEL[severity] || 'ALIEN' end def format_time(timestamp) timestamp.strftime("%b %d %H:%M:%S.#{timestamp.usec}") end def format_message(msg) msg.strip end def call(severity, timestamp, progname, msg) "#{format_severity(severity)} #{format_time(timestamp)} #{@hostname} #{progname||@app_name}[#{$$}]#{render_extra_attributes}: #{format_message(msg)}" end def render_extra_attributes (@extra_attributes || []).map{|key, value| " #{key}[#{value}]"}.join end def add_extra_attributes(attributes) (@extra_attributes ||= []).concat(attributes) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
logjam_agent-0.1.3 | lib/logjam_agent/syslog_like_formatter.rb |
logjam_agent-0.1.2 | lib/logjam_agent/syslog_like_formatter.rb |