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

Ticket #2263 (closed defect: fixed)

Opened 4 years ago

Last modified 3 years ago

Clean logger breaks with Ruby 1.8.3

Reported by: mschuerig Assigned to: rails@bitsweat.net
Priority: high Milestone: 0.9.5
Component: ActiveSupport Version: 0.13.1
Severity: major Keywords: clean logger
Cc: rtomayko@gmail.com

Description

The redefined format_message in clean_logger.rb has the arguments in the wrong order. msg is the last argument. Here's the excerpt from the original logger.rb from Ruby 1.8.3

  def format_message(severity, datetime, progname, msg)
    (@formatter || @default_formatter).call(severity, datetime, progname, msg)
  end

Attachments

clean_logger-1.8.3-compat-fix.patch (408 bytes) - added by rtomayko@gmail.com on 09/27/05 13:11:00.
Patch to fix the ordering and Format issue…

Change History

09/26/05 11:34:28 changed by court3nay

i'm not getting anything in the logs under 1.8.3 (just empty lines)..

09/26/05 12:53:10 changed by mschuerig

Sure. Does it get better when you correct the argument order of format_messages as indicated? That is, you have to make msg the last argument.

09/27/05 08:13:35 changed by wrighty

the development log comes back to life if you re-order the arguments for format_message:

<code>def format_message(severity, timestamp, progname, msg)</code>

09/27/05 13:09:53 changed by rtomayko@gmail.com

Peoples running Fedora Core 4 with the stock ruby-1.8.3 RPMs are experiencing the following in relation to this problem (quoting Ámon Tamás from mailing list):

/usr/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/clean_logger.rb:13:in `remove_const': constant Logger::Format not defined (NameError)

The problem is the next line in clean_logger.rb:

remove_const "Format"

If I comment it out it is working...

Applying both the ordering and remove_const changes (kind of), clean_logger.rb looks like this:

require 'logger'

class Logger #:nodoc:  # Silences the logger for the duration of the block.
  def silence(temporary_level = Logger::ERROR)
    old_logger_level, self.level = level, temporary_level
    yield
  ensure
    self.level = old_logger_level
  end

  private
    remove_const "Format" if defined? Format
    Format = "%s\n"
    def format_message(severity, timestamp, progname, msg)
      Format % [msg]
    end
end

I'm attaching a patch with both changes as clean_logger-1.8.3-compat-fix.patch.

09/27/05 13:11:00 changed by rtomayko@gmail.com

  • attachment clean_logger-1.8.3-compat-fix.patch added.

Patch to fix the ordering and Format issue...

09/27/05 13:11:23 changed by anonymous

  • cc set to rtomayko@gmail.com.

09/27/05 13:24:18 changed by rtomayko@gmail.com

I forgot to mention that the patch is against stable activesupport-1.1.1, not bleeding.

09/27/05 20:22:32 changed by bitsweat

  • keywords set to clean logger.
  • status changed from new to closed.
  • resolution set to fixed.

Changeset [2369]. Correctly override format_message according to RUBY_VERSION < '1.8.3' (could have also tested const_defined? Formatter or public_instance_methods.include?('formatter=')). I didn't notice this change in the 1.8.3 pre series.. hrmph!

10/07/05 15:16:47 changed by blair

  • status changed from closed to reopened.
  • resolution deleted.

Unfortunately, the solution checked into Subversion doesn't work if you're running Ubuntu 5.10 (and I'm guessing Debian sarge) because they have a heavily patched 1.8.2 version of ruby (from CVS) that reports itself as 'ruby 1.8.3 (2005-06-23) [i486-linux]' but has the logger.rb from 1.8.2. Using Rails head, I get empty log lines now with Ubuntu 5.10.

While I realize that it may not be really the job of RoR to deal with these patched version of Ruby, Debian and Ubuntu do have large user bases, so I think a better test would be to check for the capabilities of the logger class itself and not the version that ruby reports itself as.

As you suggest, we could check for const_defined? Formatter or public_instance_methods.include?('formatter=')) or even for Logger.const_defined Logger.const_defined?(:VERSION), which was also added to the 1.8.3 logger.rb.

Regards,
Blair

11/05/05 21:17:21 changed by david

  • owner changed from David to rails@bitsweat.net.
  • status changed from reopened to new.

11/05/05 22:38:40 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

Changeset [2553].