Class: Notarius::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/notarius/formatter.rb

Overview

Handles formatting of log messages. It’s compatable with Ruby’s Logger class, but has its own opinions:

  • Whitespace in the message is converted to spaces.

  • Output is truncated to 140 characters per line.

  • Timestamps are formatted as ISO 8601 in UTC.

  • Lines in call stacks are prefixed with !‘s.

  • Any of the arguments to #call can be nil.

Instance Method Summary collapse

Instance Method Details

#call(severity, timestamp, application, message) ⇒ String

Generates a formatted log statement. This is the interface Ruby’s Logger class expects.

Parameters:

  • severity (String)

    the severity level of the message

  • timestamp (Date)

    the timestamp for the message

  • application (Object)

    unused

  • message (String, #message, #backtrace, #inspect)

    the message to log

Returns:

  • (String)

    formatted as “SEVERITY [timestamp] message\n”



25
26
27
28
29
30
31
32
# File 'lib/notarius/formatter.rb', line 25

def call severity, timestamp, application, message
  lines = []
  lines << format_message(severity, timestamp, message)
  lines << format_backtrace(message)
  lines.flatten!
  lines.map! { |line| make_tweetable(line) }
  "#{lines.join("\n")}\n"
end