One thing that may be useful here: In any case, a class that is subclassed from (Rails 5.1) ActiveJob :: Base (or any instance of the class called by a class subclassed from ActiveJob :: Base). The normal Rails.logger.info('log this') commands are about to enter the rails console (presumably via STDOUT).
I did not quite understand the mechanism that this Rails.logger grab triggers, but you can switch to ActiveJob :: Base.logger and use the knowledge about it: ( https://github.com/rails/rails/blob/b205ea2dc6c70b2b8e2134640e3056ed33fdc6be/activejob/ lib / active_job / logging.rb # L13 ) to change the behavior as you like.
So this allows you to register as you want:
1) Include require "active_job/logging" in your application.rb
2) In config / development.rb (or in some environments) you should include this line:
config.active_job.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new("log/#{Rails.env}.log"))
3) Any logging inside ActiveJob subclasses, use this for logging:
ActiveJob::Base.logger.info('(MyJob) Inside of a job but not going to STDOUT')
If anyone can provide code explaining why Rails.logger.info behaves differently if inside the ActiveJob class, that would be a good read.
Dave collins
source share