Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

root/branches/1-2-stable/activesupport/lib/active_support/clean_logger.rb

Revision 3493, 1.0 kB (checked in by david, 3 years ago)

Added reusable reloading support through the inclusion of the Relodable module that all subclasses of ActiveRecord::Base, ActiveRecord::Observer, ActiveController::Base, and ActionMailer::Base automatically gets [DHH]. Added auto-loading support for classes in modules, so Conductor::Migration will look for conductor/migration.rb and Conductor::Database::Settings will look for conductor/database/settings.rb [Nicholas Seckar]. Refactored extensions to module, class, and object in active support [DHH]

Line 
1 require 'logger'
2 require File.dirname(__FILE__) + '/core_ext/class/attribute_accessors'
3
4 class Logger #:nodoc:
5   cattr_accessor :silencer
6   self.silencer = true
7
8   # Silences the logger for the duration of the block.
9   def silence(temporary_level = Logger::ERROR)
10     if silencer
11       begin
12         old_logger_level, self.level = level, temporary_level
13         yield self
14       ensure
15         self.level = old_logger_level
16       end
17     else
18       yield self
19     end
20   end
21
22   private
23     alias old_format_message format_message
24
25     # Ruby 1.8.3 transposed the msg and progname arguments to format_message.
26     # We can't test RUBY_VERSION because some distributions don't keep Ruby
27     # and its standard library in sync, leading to installations of Ruby 1.8.2
28     # with Logger from 1.8.3 and vice versa.
29     if method_defined?(:formatter=)
30       def format_message(severity, timestamp, progname, msg)
31         "#{msg}\n"
32       end
33     else
34       def format_message(severity, timestamp, msg, progname)
35         "#{msg}\n"
36       end
37     end
38 end
Note: See TracBrowser for help on using the browser.