diff options
author | Michael Koziarski <michael@koziarski.com> | 2007-06-22 23:09:11 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2007-06-22 23:09:11 +0000 |
commit | 3bf3042a6cd29fd3ccc18541e84ea8ca5c791889 (patch) | |
tree | 3f1dac05c4b0e8f90c0ce7459061e6611f58a73a /activesupport/lib/active_support/clean_logger.rb | |
parent | e682fee121ed4c48b94e0afea887370c16e15d05 (diff) | |
download | rails-3bf3042a6cd29fd3ccc18541e84ea8ca5c791889.tar.gz rails-3bf3042a6cd29fd3ccc18541e84ea8ca5c791889.tar.bz2 rails-3bf3042a6cd29fd3ccc18541e84ea8ca5c791889.zip |
Ensure clean_logger fixes are 1.8.2 compatible [mislav] Closes #8396
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7083 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/clean_logger.rb')
-rw-r--r-- | activesupport/lib/active_support/clean_logger.rb | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/clean_logger.rb b/activesupport/lib/active_support/clean_logger.rb index 65ab50e66b..7ce9faba48 100644 --- a/activesupport/lib/active_support/clean_logger.rb +++ b/activesupport/lib/active_support/clean_logger.rb @@ -44,12 +44,50 @@ class Logger formatter.datetime_format if formatter.respond_to?(:datetime_format) end - alias :old_formatter :formatter + alias :old_formatter :formatter if method_defined?(:formatter) # Get the current formatter. The default formatter is a SimpleFormatter which only # displays the log message def formatter @formatter ||= SimpleFormatter.new end + + unless const_defined? :Formatter + class Formatter + Format = "%s, [%s#%d] %5s -- %s: %s\n" + + attr_accessor :datetime_format + + def initialize + @datetime_format = nil + end + + def call(severity, time, progname, msg) + Format % [severity[0..0], format_datetime(time), $$, severity, progname, + msg2str(msg)] + end + + private + def format_datetime(time) + if @datetime_format.nil? + time.strftime("%Y-%m-%dT%H:%M:%S.") << "%06d " % time.usec + else + time.strftime(@datetime_format) + end + end + + def msg2str(msg) + case msg + when ::String + msg + when ::Exception + "#{ msg.message } (#{ msg.class })\n" << + (msg.backtrace || []).join("\n") + else + msg.inspect + end + end + end + end # Simple formatter which only displays the message. class SimpleFormatter < Logger::Formatter @@ -74,5 +112,14 @@ class Logger def format_message(severity, timestamp, msg, progname) formatter.call(severity, timestamp, progname, msg) end + + attr_writer :formatter + public :formatter= + + alias old_format_datetime format_datetime + def format_datetime(datetime) datetime end + + alias old_msg2str msg2str + def msg2str(msg) msg end end end |