monkey patching breaks Logger *again*

Hi,

I am using

(flori@lambda:~ 0)$ ruby -v; gem list activesupport|grep ^a ruby 1.8.5 (2006-12-04 patchlevel 2) [i686-linux] activesupport (1.3.1)

I experienced some problems with using Ruby's Logger class, all formatting was missing from the output after the first few lines.

In active_support/clean_logger.rb the method ::Logger#format_message is silently patched and broken, even though under 1.8.5 a Logger#formatter= method exists, that can be used to choose your own formatter implementation. In the comment there are some bad reasons given, why this is necessary. This makes it impossible to use Ruby's Logger class like it was intended to for all other clients.

I don't get it: Why doesn't Rails use its own Logger class, that may or may not derive from ::Logger, instead of breaking Ruby's standard library? It took me quite some time to track down this problem, and the reckless behavior that caused it.

Zed Shaw seemed to have exactly the same problem more than a year ago (or is this a repeated instance of it?):

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/153380

You can go read his rant, so I don't have to repeat it all. Please fix this bug in some sustainable way. Thanks for listening.

You can go read his rant, so I don't have to repeat it all. Please fix this bug in some sustainable way. Thanks for listening.

You clearly feel quite strongly about this issue, but I feel I need to remind you that rails is an open source project, and you're free to send patches. Rather than sending an angry email, you could have taken all this passion, fixed the problem, and sent us a patch to fix it.

I can see how this code can be frustrating, but the best way to make sure the fix meets your requirements, is to provide it yourself.

Michael Koziarski wrote:

You can go read his rant, so I don't have to repeat it all. Please fix this bug in some sustainable way. Thanks for listening.

You clearly feel quite strongly about this issue, but I feel I need to remind you that rails is an open source project, and you're free to send patches. Rather than sending an angry email, you could have taken all this passion, fixed the problem, and sent us a patch to fix it.

I can see how this code can be frustrating, but the best way to make sure the fix meets your requirements, is to provide it yourself.

Well, I don't feel strongly about it and I have already wasted way too much time on tracking this down. If people wonder how they can undo the damage your monkey-patching inflicts on Logger: In my application I have reversed it by doing this:

require 'active_support/clean_logger' class Logger    alias format_message old_format_message end

Here's the offending code in active_support/clean_logger.rb:

class Logger #:nodoc: [...]    private      alias old_format_message format_message

     # 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)          "#{msg}\n"        end      else        def format_message(severity, timestamp, msg, progname)          "#{msg}\n"        end      end end