Class: Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/ole/support.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.new_with_callstack(logdev = STDERR) ⇒ Object

A helper method for creating a Logger which produce call stack in their output



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ole/support.rb', line 68

def self.new_with_callstack logdev=STDERR
  log = Logger.new logdev
  log.level = WARN
  log.formatter = proc do |severity, time, progname, msg|
    # find where we were called from, in our code
    callstack = caller.dup
    callstack.shift while callstack.first =~ /\/logger\.rb:\d+:in/
    from = callstack.first.sub(/:in `(.*?)'/, ":\\1")
    "[%s %s]\n%-7s%s\n" % [time.strftime('%H:%M:%S'), from, severity, msg.to_s]
  end
  log
end