Class: LogjamAgent::SyslogLikeFormatter
- Inherits:
-
Object
- Object
- LogjamAgent::SyslogLikeFormatter
- Defined in:
- lib/logjam_agent/syslog_like_formatter.rb
Constant Summary collapse
- SEV_LABEL =
Logger::SEV_LABEL.map{|sev| "%-5s" % sev}
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
Instance Method Summary collapse
- #call(severity, timestamp, progname, msg) ⇒ Object
- #format_message(msg) ⇒ Object
- #format_severity(severity) ⇒ Object
- #format_time(timestamp) ⇒ Object
-
#initialize ⇒ SyslogLikeFormatter
constructor
A new instance of SyslogLikeFormatter.
- #render_attributes ⇒ Object
- #set_attribute(name, value) ⇒ Object
Constructor Details
#initialize ⇒ SyslogLikeFormatter
Returns a new instance of SyslogLikeFormatter.
5 6 7 8 9 |
# File 'lib/logjam_agent/syslog_like_formatter.rb', line 5 def initialize @hostname = LogjamAgent.hostname @app_name = "rails" @attributes = [] end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
11 12 13 |
# File 'lib/logjam_agent/syslog_like_formatter.rb', line 11 def attributes @attributes end |
Instance Method Details
#call(severity, timestamp, progname, msg) ⇒ Object
31 32 33 |
# File 'lib/logjam_agent/syslog_like_formatter.rb', line 31 def call(severity, , progname, msg) "#{format_severity(severity)} #{format_time()} #{@hostname} #{progname||@app_name}[#{$$}]#{render_attributes}: #{(msg)}" end |
#format_message(msg) ⇒ Object
27 28 29 |
# File 'lib/logjam_agent/syslog_like_formatter.rb', line 27 def (msg) msg.strip end |
#format_severity(severity) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/logjam_agent/syslog_like_formatter.rb', line 15 def format_severity(severity) if severity.is_a?(String) "%-5s" % severity else SEV_LABEL[severity] || 'ALIEN' end end |
#format_time(timestamp) ⇒ Object
23 24 25 |
# File 'lib/logjam_agent/syslog_like_formatter.rb', line 23 def format_time() .strftime("%b %d %H:%M:%S.#{"%06d" % .usec}") end |
#render_attributes ⇒ Object
35 36 37 |
# File 'lib/logjam_agent/syslog_like_formatter.rb', line 35 def render_attributes @attributes.map{|key, value| " #{key}[#{value}]"}.join end |
#set_attribute(name, value) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/logjam_agent/syslog_like_formatter.rb', line 39 def set_attribute(name, value) if attribute = @attributes.detect{|n,v| n == name} attribute[1] = value else @attributes << [name, value] end end |