Class: Log::Formatter

Inherits:
Object show all
Defined in:
lib/gri/log.rb

Constant Summary collapse

Format =
"%s %s\n"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#datetime_formatObject

Returns the value of attribute datetime_format.



8
9
10
# File 'lib/gri/log.rb', line 8

def datetime_format
  @datetime_format
end

Instance Method Details

#call(severity, time, progname, msg) ⇒ Object



10
11
12
13
# File 'lib/gri/log.rb', line 10

def call severity, time, progname, msg
  tstr = time.strftime("%Y-%m-%d %H:%M:%S")
  Format % [tstr, msg2str(msg)]
end

#msg2str(msg) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gri/log.rb', line 15

def msg2str(msg)
  case msg
  when ::String
	msg
  when ::Exception
	"#{ msg.message } (#{ msg.class })\n" <<
	  (msg.backtrace || []).join("\n")
  else
	msg.inspect
  end
end