Class: Log::Formatter

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

Constant Summary collapse

Format =
"%s, [%s #%d] %5s -- %s: %s\n"

Instance Method Summary collapse

Instance Method Details

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



24
25
26
27
28
29
30
# File 'lib/dnstraverse/log.rb', line 24

def call(severity, time, progname, msg)
  t = time.strftime("%Y-%m-%d %H:%M:%S.") << "%06d" % time.usec
  #t = ""
  msg2str(msg).split(/\n/).map do |m|
    Format % [severity[0..0], t, $$, severity, progname, m]
  end
end

#msg2str(msg) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/dnstraverse/log.rb', line 32

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