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 the Rails application logger #427

Merged
merged 3 commits into from
Sep 5, 2023
Merged

Use the Rails application logger #427

merged 3 commits into from
Sep 5, 2023

Conversation

etiennebarrie
Copy link
Member

Setting the logger to be the Active Job logger changes the behavior compared to using logger directly on the job: https://github.com/Shopify/job-iteration/pull/338/files#r1315002833

The reason is that previously we ended up logging to Rails.logger, because when ActiveJob initializes itself in the context of a Rails application, it sets its logger to the Rails one:
https://github.com/rails/rails/blob/v7.0.7.2/activejob/lib/active_job/railtie.rb#L13-L15

Whereas saving the value of ActiveJob::Base.logger early will use the default Active Job logger which logs to stdout:
https://github.com/rails/rails/blob/v7.0.7.2/activejob/lib/active_job/logging.rb#L11

This prevents early binding and keeps the pre-1.4.0 behavior of using the current value of ActiveJob::Base.logger during jobs.


I also directly bumped to 1.4.1 because I think this is a regression.


I investigated using a Railties to add an initializer to copy the Rails application logger later in the boot process, but ultimately found that this is simpler. It involved depending on railties, or simply defining the Railtie if the Rails::Railtie constant was defined, but it felt a bit too much (also depending on railties pulls in actionpack). Just pushing the binding later (i.e. not calling the method early and saving the result, but calling ActiveJob::Base.logger each time we need the logger) work well enough IMO.

Copy link
Contributor

@Mangara Mangara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. We'll probably want to revert #367 to release 1.4.1, as that includes a breaking change.

Since the parent of this branch is v1.4.0, we only need to merge main
ignoring its changes to this branch (the `ours` main strategy) to
effectively revert all of main's changes:

$ git merge main -s ours
Setting the logger to be the Active Job logger changes the behavior
compared to using logger directly on the job.

The reason is that previously we ended up logging to Rails.logger,
because when ActiveJob initializes itself in the context of a Rails
application, it sets its logger to the Rails one:
https://github.com/rails/rails/blob/v7.0.7.2/activejob/lib/active_job/railtie.rb#L13-L15

Whereas saving the value of ActiveJob::Base.logger early will use the
default Active Job logger which logs to stdout:
https://github.com/rails/rails/blob/v7.0.7.2/activejob/lib/active_job/logging.rb#L11

This prevents early binding and keeps the pre-1.4.0 behavior of using
the current value of ActiveJob::Base.logger during jobs.
@etiennebarrie
Copy link
Member Author

etiennebarrie commented Sep 5, 2023

I added a commit first in the branch (which starts on v1.4.0) which reverts all the changes from v1.4.0 to main by merging main but ignoring all its changes (ours strategy). Once this is merged, we'll just need to revert that merge (relative to its second parent), to reinstate all the changes.

@etiennebarrie etiennebarrie merged commit 0bfc557 into main Sep 5, 2023
40 checks passed
@etiennebarrie etiennebarrie deleted the use-rails-logger branch September 5, 2023 09:52
@shopify-shipit shopify-shipit bot temporarily deployed to rubygems September 5, 2023 09:55 Inactive
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 this pull request may close these issues.

2 participants