-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ActiveSupport::TaggedLogging no longer works (no tags are logged) #33
Comments
Workaround I'm using for now, for what it's worth: Monkeypatch
Looks like
|
After upgrading to Rails 5.2, I noticed that the last line of # activerecord-5.2.3/lib/active_record/log_subscriber.rb
def debug(progname = nil, &block)
return unless super
if ActiveRecord::Base.verbose_query_logs
log_query_source
end
end |
After upgrading from Rails 3.2 to Rails 5.1 recently, I noticed that my log files no longer included the tags specified in
config.log_tags
, even though my logger configuration hasn't changed (I'm still wrapping Lumberjack withActiveSupport::TaggedLogging.new
like I showed in #8).Rails::Rack::Logger
is the middleware that is supposed to take yourlog_tags
and add them to all log messages. But you can reproduce the same issue even more easily directly in a console...What I would expect (this used to work):
What happens instead:
No tags:
How it used to work (Rails 3.2):
Using byebug, I was able to step through my old Rails 3.2 app (same version of
lumberjack
, 1.0.12) to see the path it used to take:(Note that this used to return an instance of ActiveSupport::TaggedLogging. Now it returns an instance of Lumberjack::Logger. Kind of strange, but possibly unrelated to the issue at hand.)
As you can see,
ActiveSupport::TaggedLogging#add
used to be the method that addedtags_text
. This has changed in later version of ActiveSupport, as you can see in the next section:How it works in Rails 5 (without Lumberjack):
As you can see, the responsibility for adding
tags_text
has moved fromActiveSupport::TaggedLogging#add
in Rails 3 toActiveSupport::TaggedLogging::Formatter#call
in Rails 5. The problem is, thatcall
never gets called if we use Lumberjack...How it doesn't work in Rails 5 with Lumberjack
If I change this line:
to this:
Then:
You can see that it starts out identically...
That method is pretty much the same as
Logger
's, but here is where it really starts to diverge:As you can see,
@formatter
is aLumberjack::Formatter
andActiveSupport::TaggedLogging::Formatter#call
never gets called, so the log tags never get added.Have also tested in a simple, bare-bones Rails 5.2 app and observe the same behavior.
Summary
So I'm wondering, is
ActiveSupport::TaggedLogging
's formatter fundamentally incompatible with Lumberjack's formatter system? Or are we expected to register that formatter with Lumberjack somehow?Was it just coincidence that
ActiveSupport::TaggedLogging
worked with Lumberjack before without any special configuration, or is it supposed to still work now? If so, how do we fix it?One or both sides seem to be breaking a promise here.
ActiveSupport::TaggedLogging
claims:while Lumberjack claims:
Could someone who understands the logger situation better please explain why they don't seem to play nicely together and what the recommended solution would be?
The text was updated successfully, but these errors were encountered: