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

Not all loggers have a formatter #502

Closed
adibsaad opened this issue Jan 29, 2022 · 3 comments · Fixed by #504
Closed

Not all loggers have a formatter #502

adibsaad opened this issue Jan 29, 2022 · 3 comments · Fixed by #504

Comments

@adibsaad
Copy link

tags_for_logger = if each_logger.formatter.current_tags.include?("ActiveJob")

each_logger.formatter can be nil

Issue mentioned in reidmorrison/rails_semantic_logger#29

@bensheldon
Copy link
Owner

Thanks for the heads up! That can be feature-tested for in GoodJob.

Looks like tagged logging might also be a problem too.

@adibsaad
Copy link
Author

Thanks for the quick response.

Another observation: using the fix I put in that issue, GoodJob starts logging twice, once with its own logger (I'm guessing) and one with Rails.logger

[GoodJob] [88944] GoodJob started scheduler with queues=* max_threads=5.
2022-01-29 18:44:39.517917 I [88944:63220] [GoodJob] [88944] Rails -- GoodJob started scheduler with queues=* max_threads=5.
[GoodJob] GoodJob started cron with 2 jobs.
2022-01-29 18:44:39.954994 I [88944:63220] [GoodJob] Rails -- GoodJob started cron with 2 jobs.
[GoodJob] Notifier subscribed with LISTEN
2022-01-29 18:44:40.078149 I [88944:GoodJob::Notifier-worker-1] [GoodJob] Rails -- Notifier subscribed with LISTEN

@bensheldon
Copy link
Owner

bensheldon commented Jan 30, 2022

Looking at this now. My assumption was that any logger that is a tagged logger would have a populated formatter. I can guard against that being nil too.

if each_logger.respond_to?(:tagged)
tags_for_logger = if each_logger.formatter.current_tags.include?("ActiveJob")

Also, I was curious why GoodJob has this problem because I borrowed the log tagging structure from ActiveJob. Looks like SemanticLogger monkey patches Rails:

https://github.com/reidmorrison/rails_semantic_logger/blob/e83a306296670f205aa6adae9017528d22a8191c/lib/rails_semantic_logger/extensions/active_job/logging.rb

Here's the original method in ActiveJob that SemanticLogger patched around, which calls the formatter:

https://github.com/rails/rails/blob/de956f57733b309e5f7a0be1e9f86ab3e9160c64/activejob/lib/active_job/logging.rb#L22-L33

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.

2 participants