Skip to content
This repository has been archived by the owner on Nov 1, 2017. It is now read-only.

Fix NoMethodError when using a custom Rails.logger class #84

Merged
merged 1 commit into from Oct 23, 2015
Merged

Fix NoMethodError when using a custom Rails.logger class #84

merged 1 commit into from Oct 23, 2015

Conversation

alexpeattie
Copy link
Contributor

Currently if you set your Rails.logger to some other class, e.g.

# config/application.rb
config.logger = Logger.new(STDOUT)

ActionCable throws an error when it gets a connection

Rack app error: #<NoMethodError: undefined method `tagged' for #<Logger:0x007fa001c50ca8>
/Users/alex/Documents/actioncable/lib/action_cable/connection/tagged_logger_proxy.rb:25:in `log'
/Users/alex/Documents/actioncable/lib/action_cable/connection/tagged_logger_proxy.rb:19:in `block (2 levels) in <class:TaggedLoggerProxy>'
/Users/alex/Documents/actioncable/lib/action_cable/connection/base.rb:72:in `process'
/Users/alex/Documents/actioncable/lib/action_cable/server/base.rb:21:in `call'

Because the TaggedLoggerProxy class expects the logger to implement a tagged method - which is only true if the logger is an instance ActiveSupport::TaggedLogging (i.e. the default Rails.logger)

This PR fixes it by only wrapping loggers that respond to tagged in the TaggedLoggerProxy. An alternative could be to ensure our logger is an instance of ActiveSupport::TaggedLogging:

logger = ActiveSupport::TaggedLogging.new(server.logger)

But it seems like it makes more sense to leave the Rails.logger untouched if the app's using a non-default logger?

Potentially related to #57

rafaelfranca added a commit that referenced this pull request Oct 23, 2015
Fix NoMethodError when using a custom Rails.logger class
@rafaelfranca rafaelfranca merged commit 1db8c56 into rails:master Oct 23, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
2 participants