2004-12-29 16:03:21 -05:00
|
|
|
require 'logger'
|
2005-10-23 16:00:05 -04:00
|
|
|
require File.dirname(__FILE__) + '/class_attribute_accessors'
|
2004-12-29 16:03:21 -05:00
|
|
|
|
|
|
|
class Logger #:nodoc:
|
2005-10-23 16:00:05 -04:00
|
|
|
cattr_accessor :silencer
|
|
|
|
self.silencer = true
|
|
|
|
|
2005-05-02 07:41:24 -04:00
|
|
|
# Silences the logger for the duration of the block.
|
2005-05-02 13:20:18 -04:00
|
|
|
def silence(temporary_level = Logger::ERROR)
|
2005-10-23 16:00:05 -04:00
|
|
|
if silencer
|
|
|
|
begin
|
|
|
|
old_logger_level, self.level = level, temporary_level
|
|
|
|
yield self
|
|
|
|
ensure
|
|
|
|
self.level = old_logger_level
|
|
|
|
end
|
|
|
|
else
|
|
|
|
yield self
|
|
|
|
end
|
2005-05-02 07:41:24 -04:00
|
|
|
end
|
|
|
|
|
2004-12-29 16:03:21 -05:00
|
|
|
private
|
2005-10-13 15:05:32 -04:00
|
|
|
# Ruby 1.8.3 transposed the msg and progname arguments to format_message.
|
|
|
|
# We can't test RUBY_VERSION because some distributions don't keep Ruby
|
|
|
|
# and its standard library in sync, leading to installations of Ruby 1.8.2
|
|
|
|
# with Logger from 1.8.3 and vice versa.
|
|
|
|
if method_defined?(:formatter=)
|
|
|
|
def format_message(severity, timestamp, progname, msg)
|
2005-09-27 16:18:55 -04:00
|
|
|
"#{msg}\n"
|
|
|
|
end
|
|
|
|
else
|
2005-10-13 15:05:32 -04:00
|
|
|
def format_message(severity, timestamp, msg, progname)
|
2005-09-27 16:18:55 -04:00
|
|
|
"#{msg}\n"
|
|
|
|
end
|
2004-12-29 16:03:21 -05:00
|
|
|
end
|
2005-09-27 16:18:55 -04:00
|
|
|
end
|