Class: Loggable::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/rhuidean/loggable.rb

Overview

I use this to override the log formatting. There's no documented way to do this; I had to figure it out. That means this could break, and it's not "right."

Constant Summary

FORMAT =
"%s, [%s] %s: %s\n"
PN_RE =
/\:in \`.+\'/

Instance Method Summary (collapse)

Instance Method Details

- (Object) call(severity, time, progname, msg)

Called by Logger to format the message.


severity

String

time

Time

progname

String

msg

strictly anything, for us String



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rhuidean/loggable.rb', line 31

def call(severity, time, progname, msg)
    datetime = time.strftime('%m/%d %H:%M:%S')

    # Include filename, line number, and method name in debug
    if severity == "DEBUG"
        progname.gsub!(PN_RE, '')
        progname.gsub!('block in ', '')
        "[%s] %s: %s\n" % [datetime, progname, msg]
    else
        "[%s] %s\n" % [datetime, msg]
    end
end