Skip to content
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

Wrap Logging::Logger with ActiveSupport::TaggedLogging #20

Open
sshaw opened this issue Jun 6, 2015 · 3 comments
Open

Wrap Logging::Logger with ActiveSupport::TaggedLogging #20

sshaw opened this issue Jun 6, 2015 · 3 comments

Comments

@sshaw
Copy link

sshaw commented Jun 6, 2015

By default Rails.logger is wrapped. When migrating to logging-rails I usually end up doing this. Any reason not to do this in the initializer?

@TwP
Copy link
Owner

TwP commented Jun 7, 2015

Logging provides the nested diagnostic context that does exactly this. You can also used the mapped diagnostic context to attach named attributes to each log message.

Logging.ndc.push("fact1") {
  logger.info("some message")
}

You can also nest these contexts. The block format is optional (although convenient).

Logging.ndc.push("fact1")
# lots of other code
Logging.ndc.push("fact2") {
  logger.info("another message")
}
# and even more code
Logging.ndc.pop

@sshaw
Copy link
Author

sshaw commented Jun 7, 2015

Logging provides the nested diagnostic context that does exactly this. You can also used the mapped diagnostic context

Yes, I'm familiar with these, but why force one to cook up something custom
just to get what Rails provides out of the box by assigning Procs or Symbols to config.log_tags?

Of course it's trivial for one to wrap Logging::Logger with ActiveSupport::TaggedLogging, but
this is logging-rails. It should integrate logging with Rails' features, not the other way around 😸

@sshaw
Copy link
Author

sshaw commented Jun 7, 2015

Though there is one thing to note: Rails will wrap all loggers (ActiveRecord, ActionController, etc...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants