Activesupport::TaggedLogging
This is an unofficial extraction of Rails' v8 ActiveSupport::TaggedLogging
which has been:
- refactored (here) to work with broadcast logging, and
- backported to work with Rails v5.2+ and Ruby 2.7+.
If the suite of gems this is part of is loaded in any version of Rails >= 5.2, it will replace the logging tooling completely.
This gem automatically depends on and configures the other gems in the suite. Simply add it to your Gemfile, and configure. The other gems will just work.
Simplified, the load order is basically:
- Enhanced activesupport-logger which was ripped from Rails v8.0
- Enhanced activesupport-broadcast_logger which was ripped from Rails v8.0, and this PR
- Enhanced activesupport-tagged_logging (this gem) which was ripped from Rails v8.0, and this PR
Above load order is handled for you in activesupport-tagged_logging (this gem), so depend on this gem, not the siblings. ;)
Installation
Install the gem and add to the application's Gemfile by executing:
$ bundle add activesupport-tagged_logging
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install activesupport-tagged_logging
Usage
When it doesn't work
NameError: uninitialized constant ActiveSupport::TaggedLogging
The issue is likely that canonical active_support
has been loaded before this gem had a chance to load.
This is a common issue, see the following for more context:
- soutaro/steep#484
- santry/json_tagged_logger#22
-
VitalConnectInc/rails#1
- Rails itself loads
active_support
, incorrectly, internally! - When I get time I want to document this and submit a PR to Rails core.
- Rails itself loads
- VitalConnectInc/webpacker#3
This gem has a solution for all of the above, but it only works if this gem is loaded first.
Keep reading below.
With Rails
In a Rails project change config/boot.rb
to match:
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
require "bundler/setup" # Set up gems listed in the Gemfile.
# NOTE: needs to load before active_support, so the magic will work.
require "activesupport-tagged_logging"
require "bootsnap/setup" # Speed up boot time by caching expensive operations.
With Sidekiq
You won't be able to use bundle exec sidekiq
, as that results in loading active_support
too early.
However, you should have a bin/sidekiq
binstub, which can be fixed to load activesupport-tagged_logging
early!
Change the last few lines of bin/sidekiq to match:
require "rubygems"
require "bundler/setup"
# NOTE: needs to load before active_support, so the magic will work.
# sidekiq, when loaded in Rails, loads active_job,
# which depends on active_support, hence this early load hack.
require "activesupport-tagged_logging"
load Gem.bin_path("sidekiq", "sidekiq")
With activesupport-logger
gem
activesupport-logger is automatically depended on and configured by this gem, so you don't need to do anything else.
IMPORTANT: When using this gem,
do not require "activesupport-logger"
in your code.
Load order matters.
With activesupport-broadcast_logger
gem
activesupport-broadcast_logger is automatically depended on and configured by this gem, so you don't need to do anything else.
IMPORTANT: When using this gem,
do not require "activesupport-broadcast_logger"
in your code.
Load order matters.
With broadcasting support
If you want to try an experimental fix from a PR, run:
Activesupport::FixPr53105.init
NOTE: The bits of logic that are unique to this gem are in the namespace Activesupport
(sic).
See: https://github.com/rails/rails/pull/53105/files
General Info
Primary Namespaces |
Activesupport::TaggedLogging && ActiveSupport::TaggedLogging && Activesupport::FixPr53105
|
---|---|
documentation | on Github.com, Latest release on RubyDoc.info, HEAD on RubyDoc.info |
expert support | |
... 💖 |
💻 🌏 |
🤝 Contributing
If you need some ideas of where to help, you could work on adding more code coverage, or if it is already 💯 then check issues, or PRs, or use the gem and think about how it could be better.
Also, see CONTRIBUTING.md.
Code Coverage
🌈 Contributors
Made with contributors-img.
Star History
🪇 Code of Conduct
Everyone interacting in this project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
📌 Versioning
This Library adheres to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions.
To get a better understanding of how SemVer is intended to work over a project's lifetime, read this article from the creator of SemVer:
As a result of this policy, you can (and should) specify a dependency on these libraries using the Pessimistic Version Constraint with two digits of precision.
For example:
spec.add_dependency("activesupport-tagged_logging", "~> 2.0")
See CHANGELOG.md for list of releases.
📄 License
The gem is available as open source under the terms of the MIT License .
See LICENSE.txt for the official Copyright Notice.
© Copyright
- Copyright (c) David Heinemeier Hansson
- Parts original to this extraction are:
- Copyright (c) 2024 Peter H. Boling of Rails Bling
🤑 One more thing
You made it to the bottom of the page, so perhaps you'll indulge me for another 20 seconds. I maintain many dozens of gems, including this one, because I want Ruby to be a great place for people to solve problems, big and small. Please consider supporting my efforts via the giant yellow link below, or one of the others at the head of this README.