Class: RightScale::Log::Formatter
- Defined in:
- lib/right_agent/log.rb
Overview
Default formatter for a Log
Constant Summary collapse
- @@show_time =
true
Instance Method Summary collapse
-
#call(severity, time, progname, msg) ⇒ Object
Prints a log message as ‘datetime progname: message’ if @@show_time == true; otherwise, doesn’t print the datetime.
-
#msg2str(msg) ⇒ Object
Converts some argument to a Logger.severity() call to a string Regular strings pass through like normal, Exceptions get formatted as “message (class)nbacktrace”, and other random stuff gets put through “object.inspect”.
-
#show_time=(show = false) ⇒ Object
Set whether to show time in logged messages.
Instance Method Details
#call(severity, time, progname, msg) ⇒ Object
Prints a log message as ‘datetime progname: message’ if @@show_time == true; otherwise, doesn’t print the datetime
Parameters
- severity(String)
-
Severity of event
- time(Time)
-
Date-time
- progname(String)
-
Program name
- msg(Object)
-
Message object that can be converted to a string
Return
Formatted message
69 70 71 72 73 74 75 |
# File 'lib/right_agent/log.rb', line 69 def call(severity, time, progname, msg) if @@show_time sprintf("%s %s[%d]: %s\n", format_datetime(time), progname, Process.pid, msg2str(msg)) else sprintf("%s[%d]: %s\n", progname, Process.pid, msg2str(msg)) end end |
#msg2str(msg) ⇒ Object
Converts some argument to a Logger.severity() call to a string Regular strings pass through like normal, Exceptions get formatted as “message (class)nbacktrace”, and other random stuff gets put through “object.inspect”
Parameters
- msg(Object)
-
Message object to be converted to string
Return
String
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/right_agent/log.rb', line 87 def msg2str(msg) case msg when ::String msg when ::Exception "#{ msg. } (#{ msg.class })\n" << (msg.backtrace || []).join("\n") else msg.inspect end end |
#show_time=(show = false) ⇒ Object
Set whether to show time in logged messages
Parameters
- show(Boolean)
-
Whether time should be shown
54 55 56 |
# File 'lib/right_agent/log.rb', line 54 def show_time=(show=false) @@show_time = show end |