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

ActiveSupport::Logger getting "hijacked" by Rails Semantic Logger? #141

Open
gingerlime opened this issue Nov 1, 2021 · 3 comments
Open

Comments

@gingerlime
Copy link

gingerlime commented Nov 1, 2021

This is more of a question ... We're not entirely sure what's happening under the hood here, but it feels strange.

Environment

  • Ruby 3.0.2
  • Rails Version 6.1.4.1
  • Semantic Logger Version 4.8.1
  • Rails Semantic Logger Version 4.6.1
  • Other Application/framework names and versions (e.g. Puma, etc.). Webpacker 5.4.3

Hope this image explains the issue?

image

This was initially reported on rails/webpacker#3208

It seems like rails semantic logger "hijacks" ActiveSupport::Logger in some way, and then when Webpacker uses ActiveSupport::Logger.new(STDOUT), it doesn't return an ActiveSupport::Logger instance, and the Rails semantic logger instance being returned does not actually log to stdout ?

Expected Behavior

Logs to stdout

Actual Behavior

Does not log to stdout.

@reidmorrison
Copy link
Owner

Semantic Logger is as clean as I can make it, but Rails Semantic Logger is nothing but a huge ugly hack to try and get Rails to log in a Semantic (machine readable) way. All of the hackery goes on in here: https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/engine.rb

If Rails adopted Semantic Logger directly we could just delete Rails Semantic Logger entirely.

To fix the stdout logging problems with Rails, we used this hack: https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/extensions/rails/server.rb

A similar patch for Web Packer would send all log messages to the right place.

@gingerlime
Copy link
Author

Thank you @reidmorrison. It's hard for me to say, since I'm not deeply familiar with ruby logging or the rails internals. Have you considered submitting a PR to improve the Rails logging? I'm sure the community can benefit from your experience. Perhaps you can also propose integrating SemanticLogger into Rails? I'd be happy to "vouch" for it, FWIW :)

Wishing you a happy holiday season and a very happy and healthy 2022. Thanks for contributing your time and energy into open-source. I know it's not easy and not everyone is grateful, but I certainly appreciate your work, and the work of many other open-source contributors. I also try to contribute where I can, on my "own" projects and others like SemanticLogger. If there's anything I can do more to help, please let me know and I'll do my best to help.

@viktorianer
Copy link

Not sure if it helps, but Rails logs now to STDOUT by default, see rails/rails#47138.

Could we modify the following lines, to provide a different format and logger?

config.logger = ActiveSupport::Logger.new(STDOUT)
    .tap  { |logger| logger.formatter = ::Logger::Formatter.new }
    .then { |logger| ActiveSupport::TaggedLogging.new(logger) }

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

No branches or pull requests

3 participants