JobEnqueueLogger
Log background jobs enqueued by your application (additionally with backtraces). Helps with debugging, or just generally understanding what's going on under the hood. Useful for finding where to start when making changes to a large application.
This is very much a development and debugging tool; it is not recommended to use this in a production environment as it is monkey-patching the respective job queuing implementations. You have been warned - use at your own risk.
Example
When the job is enqueued within the guts of the application, the log line is generated:
[JobEnqueueLogger] Enqueued AvatarThumbnailsJob (jid=578b3d10fc5403f97ee0a8e1) to Sidekiq(default) with arguments: 1092412064
Or with backtraces enabled:
[JobEnqueueLogger] Enqueued AvatarThumbnailsJob (jid=578b3d10fc5403f97ee0a8e1) to Sidekiq(default) with arguments: 1092412064
β³ app/models/user.rb:421:in `generate_avatar_thumbnails'
app/services/user_creator.rb:21:in `call'
app/controllers/users_controller.rb:49:in `create'
Requirements
Requires ruby > 2.7.
This gem supports most common job queuing backends:
- Sidekiq >= 6.5.0
- Resque >= 2.0.0
- DelayedJob >= 4.1.5
- SuckerPunch >= 3.0.0
- Que >= 2.0.0
If you need support for older rubies or older versions of queuing backends (or additional backends), open an issue.
Installation
Add this line to your application's Gemfile:
# Add this *after* your job queuing gem of choice
gem 'job_enqueue_logger', group: :development
And then execute:
$ bundle
Or install it yourself as:
$ gem install job_enqueue_logger
Configuration
You can override the following default options:
JobEnqueueLogger.configure do |config|
# Controls the contents of the printed backtrace.
# Is set to default Rails.backtrace_cleaner, when the gem is used in the Rails app.
config.backtrace_cleaner = ->(backtrace) { backtrace }
# Controls whether to print backtraces. Set to `true` to print backtraces, or
# a number to limit how many lines to print.
config.backtrace = false
# The logger to log to.
# Is set to Rails.logger by default, when the gem is used in the Rails app.
config.logger = nil
end
Development
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/fatkodima/job_enqueue_logger.
License
The gem is available as open source under the terms of the MIT License.