Class: ScoutAgent::WireTap::Formatter

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeFormatter

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_formatObject

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, message)
  FORMAT % [ severity,
             format_time(time),
             format_progname(progname),
             format_message(message) ]
end