Class: RightScale::Log::Formatter

Inherits:
Logger::Formatter
  • Object
show all
Defined in:
lib/right_agent/log.rb

Overview

Default formatter for a Log

Constant Summary collapse

@@show_time =
true

Instance Method Summary collapse

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



70
71
72
73
74
75
76
# File 'lib/right_agent/log.rb', line 70

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



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/right_agent/log.rb', line 88

def msg2str(msg)
 case msg
 when ::String
   msg
 when ::Exception
   "#{ msg.message } (#{ 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



55
56
57
# File 'lib/right_agent/log.rb', line 55

def show_time=(show=false)
  @@show_time = show
end