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

Use existing TaggedLogger instead of re-wrapping it with TaggedLogging #488

Closed
kriansa opened this issue Feb 19, 2024 · 4 comments · Fixed by #489
Closed

Use existing TaggedLogger instead of re-wrapping it with TaggedLogging #488

kriansa opened this issue Feb 19, 2024 · 4 comments · Fixed by #489

Comments

@kriansa
Copy link
Contributor

kriansa commented Feb 19, 2024

initializer "dotenv", after: :initialize_logger do |app|
# Set up a new logger once Rails has initialized the logger and replay logs
new_logger = ActiveSupport::TaggedLogging.new(::Rails.logger).tagged("dotenv")
logger.replay new_logger if logger.respond_to?(:replay)
self.logger = new_logger
end

This initializer wraps the existing Rails logger into ActiveSupport::TaggedLogging, which for the default Rails config is not bad, but when custom loggers are in place, it could be troublesome.

I, for instance, currently have a custom logger that mimics TaggedLogging and supports its interface. I think we should just test if the existing Rails logger responds to .tagged and then call it instead of re-wrapping it. Something like that (haven't tested yet):

 initializer "dotenv", after: :initialize_logger do |app| 
   # Set up a new logger once Rails has initialized the logger and replay logs 
   new_logger = ::Rails.logger&.tagged("dotenv") || ::Rails.logger
   logger.replay new_logger if logger.respond_to?(:replay) 
   self.logger = new_logger 
 end 

What do you think? By the way, awesome work on the new release! 👍

@bkeepers
Copy link
Owner

@kriansa Yep, that sounds reasonable. Do you want to work up a pull request with tests?

@kriansa
Copy link
Contributor Author

kriansa commented Feb 19, 2024

Sure, will send a patch shortly

@kriansa
Copy link
Contributor Author

kriansa commented Feb 20, 2024

@bkeepers I opened a PR, (#489). Lmk if it looks ok

@dtbaker
Copy link

dtbaker commented Feb 25, 2024

interesting, I just bumped activesupport from 7.0.8 to 7.0.8.1 and hit this error

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

Successfully merging a pull request may close this issue.

3 participants