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

Ticket #2245 (closed defect: fixed)

Opened 3 years ago

Last modified 2 years ago

[PATCH] Logger/ActiveSupport broken with Ruby 1.8.3?

Reported by: michael@schubert.cx Assigned to: David
Priority: high Milestone:
Component: ActiveSupport Version: 0.13.1
Severity: critical Keywords: logger
Cc:

Description

So it looks like Ruby 1.8.3 doesn't play well with Rails (trunk) giving the following error:

./script/../config/../vendor/rails/activesupport/lib/active_support/clean_logger.rb:13:in `remove_const': constant Logger::Format not defined (NameError)

from ./script/../config/../vendor/rails/activesupport/lib/active_support/clean_logger.rb:13 from ./script/../config/../vendor/rails/activesupport/lib/active_support.rb:31 from ./script/../config/environment.rb:56 from script/server:42

Looking at the code.. we're just trying to remove it anyways so we can redefine it.. so simply check to see if its defined before trying to remove the constant.

Attachments

as_clean_logger_rb.patch (456 bytes) - added by michael@schubert.cx on 09/21/05 03:59:22.
Patch to check before trying to remove a non-existant constant Format
as_clean_logger_rb-fixed.patch (449 bytes) - added by michael@schubert.cx on 09/21/05 04:07:13.
Yeah let's get the Namespace right this time Schubert :-)
clean_logger.rb (187 bytes) - added by sugito on 01/06/06 09:35:45.
clean_logger.2.rb (187 bytes) - added by sugito on 01/06/06 09:37:39.

Change History

09/21/05 03:59:22 changed by michael@schubert.cx

  • attachment as_clean_logger_rb.patch added.

Patch to check before trying to remove a non-existant constant Format

09/21/05 04:01:14 changed by michael@schubert.cx

  • priority changed from normal to highest.
  • severity changed from normal to critical.
  • summary changed from Logger/ActiveSupport broken with Ruby 1.8.3? to [PATCH] Logger/ActiveSupport broken with Ruby 1.8.3?.

Upping priority

09/21/05 04:07:13 changed by michael@schubert.cx

  • attachment as_clean_logger_rb-fixed.patch added.

Yeah let's get the Namespace right this time Schubert :-)

09/21/05 04:44:06 changed by michael@schubert.cx

  • cc set to mathieu@ubertor.com.

Well according to David Black and ruby-lang Logger::Format is now Logger::Formatter::Format ... This is probably a bigger issue than just a simple patch.

09/21/05 04:50:09 changed by michael@schubert.cx

  • cc deleted.

I'm sorry about the spam mathieu, for some bloody reason safari feels like it should auto-fill in the Cc field in tracks for me by copying the data from a previous bug.

09/21/05 06:38:39 changed by nakahiro@gmail.com

Please use Logger#formatter= if defined such as;

logger.formatter = proc { |severity, timestamp, progname, msg| "#{msg}\n" }

you can just call Logger#<< if you don't need level filtering;

logger << "#{msg}\n"

09/21/05 13:45:19 changed by david

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

Actually here's an even simpler implementation that works in both:

    def format_message(severity, timestamp, msg, progname)
      "#{msg}\n"
    end

We can't use logger.formatter= since that would require changes for each instance and logger << would require changes in the calls.

09/21/05 18:06:12 changed by nakahiro@gmail.com

Why don't you implement new logger class by yourself? (as a wrapper of Logger or a new class) Overwriting existing definition is considered harmful even if you can do it in Ruby.

09/21/05 18:09:46 changed by david

That's also a good idea nakahiro. The logging in Rails could definitely use some additional love. I know clean_logger is rude.

01/06/06 09:35:45 changed by sugito

  • attachment clean_logger.rb added.

01/06/06 09:37:39 changed by sugito

  • attachment clean_logger.2.rb added.

04/24/06 05:35:12 changed by wrfroelich@yahoo.com

I was using the format_message method and found that the order of the parameters was switched. I'm on Ruby 1.8.4 / Ror 1.1.2

    def format_message(severity, timestamp, progname, msg)
      "#{msg}\n"
    end

and it provided the formatting control I expected.