Class: ScoutAgent::WireTap::Formatter
- Inherits:
-
Object
- Object
- ScoutAgent::WireTap::Formatter
- Defined in:
- lib/scout_agent/wire_tap.rb
Overview
Instances of this Class are used to format all outgoing log messages.
WireTap will pass messages to call() which is expected to return a String ready for output.
This class works very similar to Logger’s default formatter (supporting things like logging Exception backtraces and Ruby objects with inspect()) with the following changes:
-
The default message format is simplified
-
The default timestamp format is more readable
-
All lines after the first in a logged message are indented
-
Program names are shown with an attached PID
Constant Summary collapse
- FORMAT =
The sprintf() style format used to format messages:
SEVERITY [TIME PROCESS]: MESSAGE
"%s [%s %s]: %s\n"
Instance Attribute Summary collapse
-
#datetime_format ⇒ Object
Used to manually set the timestamp format, overriding the default.
Instance Method Summary collapse
-
#call(severity, time, progname, message) ⇒ Object
The main interface required by Formatter instances.
-
#initialize ⇒ Formatter
constructor
Creates a new formatter without a timestamp format.
Constructor Details
#initialize ⇒ Formatter
Creates a new formatter without a timestamp format.
55 56 57 |
# File 'lib/scout_agent/wire_tap.rb', line 55 def initialize @datetime_format = nil end |
Instance Attribute Details
#datetime_format ⇒ Object
Used to manually set the timestamp format, overriding the default.
60 61 62 |
# File 'lib/scout_agent/wire_tap.rb', line 60 def datetime_format @datetime_format end |
Instance Method Details
#call(severity, time, progname, message) ⇒ Object
The main interface required by Formatter instances. Turns severity
, time
, progname
, and message
into a String for writing to a log file.
67 68 69 70 71 72 |
# File 'lib/scout_agent/wire_tap.rb', line 67 def call(severity, time, progname, ) FORMAT % [ severity, format_time(time), format_progname(progname), () ] end |