Skip to content

Commit

Permalink
Use the Rails application logger
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
etiennebarrie committed Sep 5, 2023
1 parent 73fc625 commit 604f43e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GIT
PATH
remote: .
specs:
job-iteration (1.4.0)
job-iteration (1.4.1)
activejob (>= 5.2)

GEM
Expand Down
8 changes: 6 additions & 2 deletions lib/job-iteration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ module JobIteration

extend self

attr_accessor :logger
attr_writer :logger

self.logger = ActiveJob::Base.logger
class << self
def logger
@logger || ActiveJob::Base.logger
end
end

# Use this to _always_ interrupt the job after it's been running for more than N seconds.
# @example
Expand Down
2 changes: 1 addition & 1 deletion lib/job-iteration/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module JobIteration
VERSION = "1.4.0"
VERSION = "1.4.1"
end

0 comments on commit 604f43e

Please sign in to comment.