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

Ticket #9667 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

[PATCH] ActiveSupport::BufferedLogger bug -- missing methods

Reported by: DrMark Assigned to: core
Priority: high Milestone: 1.x
Component: ActionPack Version: edge
Severity: normal Keywords: tested action_controller, active_record, tested, logger
Cc: chuyeow

Description

DHH is probably already aware of this but:

The new ActiveSupport::BufferedLogger is missing a few methods used in other places in Rails.

To verify this, in a console do:

a = Logger.new(STDOUT)

=> #<Logger:0x37eaca4 @default_formatter=#<Logger::Formatter:0x37eac7c @datetime_format=nil>, @progname=nil, @logdev=#<Logger::LogDevice:0x37eac54 @shift_size=nil, @shift_age=nil, @filename=nil, @mutex=#<Logger::LogDevice::LogDeviceMutex:0x37eac2c @mon_waiting_queue=[], @mon_entering_queue=[], @mon_count=0, @mon_owner=nil>, @dev=#<IO:0x22b7d0>>, @level=0, @formatter=nil>

b = ActiveSupport::BufferedLogger.new(STDOUT)

=> #<ActiveSupport::BufferedLogger:0x37d8658 @buffer="", @auto_flushing=true, @log=#<IO:0x22b7d0>, @level=0>

(a.methods.sort - Logger.parent.methods.sort) - (b.methods.sort - ActiveSupport::BufferedLogger.parent.methods.sort)

=> ["<<", "add", "around_debug", "around_error", "around_fatal", "around_info", "datetime_format", "datetime_format=", "formatter", "formatter=", "log", "old_datetime_format", "old_datetime_format=", "old_formatter", "progname", "progname=", "sev_threshold", "sev_threshold="]

Note the missing "add" method.

This is used in

actionpack/lib/action_controller/benchmarking.rb line 27

logger.add(log_level, "#{title} (#{'%.5f' % seconds})")

and

activerecord/lib/active_record/base.rb line 942

logger.add(log_level, "#{title} (#{'%.5f' % seconds})")

several of the other missing methods are used in Rails as well, like

logger.datetime_format logger.formatter

Attachments

buffered_logger_add.diff (0.6 kB) - added by chuyeow on 09/25/07 06:46:08.
Adds BufferedLogger#add (tiny, no tests)
fix_buffered_logger_to_better_conform_to_logger_contract.diff (2.5 kB) - added by tomafro on 09/25/07 11:14:25.

Change History

09/25/07 06:20:43 changed by chuyeow

Patch for BufferedLogger#add here: #9668. Please +1 if it works for you :)

I think David left out the formatter on purpose as you can see from his check-in comment.

09/25/07 06:21:07 changed by chuyeow

  • cc set to chuyeow.

(in reply to: ↑ description ) 09/25/07 06:28:23 changed by eigentone

I have posted a patch that adds the add method: http://dev.rubyonrails.org/ticket/9669

09/25/07 06:41:15 changed by manfred

chuyeow and eigentone, can you merge your patches close your tickets and add the result to this ticket?

09/25/07 06:46:08 changed by chuyeow

  • attachment buffered_logger_add.diff added.

Adds BufferedLogger#add (tiny, no tests)

09/25/07 06:47:56 changed by chuyeow

Sure manfred, I added my ticket before I realized there was another one open, sorry about that.

Attached my tiny patch.

09/25/07 08:04:04 changed by DrMark

Note that all of the following methods are missing:

["<<", "add", "around_debug", "around_error", "around_fatal", "around_info", "datetime_format", "datetime_format=", "formatter", "formatter=", "log", "old_datetime_format", "old_datetime_format=", "old_formatter", "progname", "progname=", "sev_threshold", "sev_threshold="]

only logger.datetime_format logger.formatter appear to be used in Rails code. I would write a patch for the missing methods, but it is difficult to find references for some of these methods (not in source or api.rubyonrails.org)

09/25/07 09:17:49 changed by iabbott

This seems to prevent the rendering of any partials whatsoever in development mode.

It seems that render_partial() in vendor/rails/actionpack/lib/action_view/partials.rb calls ActionController::Base.benchmark() if a logger is present. That method calls the logger.add() method which is missing on the new BufferedLogger. As a result, nothing renders apart from a NoMethodError.

09/25/07 09:57:03 changed by tomafro

  • keywords changed from action_controller, active_record to action_controller, active_record, tested, logger.
  • summary changed from ActiveSupport::BufferedLogger bug -- missing methods to [PATCH] ActiveSupport::BufferedLogger bug -- missing methods.

Taking eigentone's patch as a base, I've added a patch that adds an implementation of BufferedLogger#add, and fixes the implementations of #info, #debug, etc. to use this method and allow messages passed as blocks. E.g

logger.debug {build_complex_debug_message}

The other missing methods are (IMO) redundant with respect to the buffered logger

09/25/07 09:59:25 changed by tomafro

  • keywords changed from action_controller, active_record, tested, logger to tested action_controller, active_record, tested, logger.

09/25/07 10:47:49 changed by tom

I'm pretty sure you mean \n, not \\n, on line 55 of buffered_logger.rb.

09/25/07 11:14:25 changed by tomafro

  • attachment fix_buffered_logger_to_better_conform_to_logger_contract.diff added.

09/25/07 11:15:21 changed by tomafro

Good spot. I removed one \\n from the original code but not the other. Fixed now.

09/25/07 16:06:11 changed by tom

I should probably also add: +1.

09/25/07 16:42:44 changed by david

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