Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement broadcasting logs to other loggers, following the same interface as `#broadcast_to`. Unlike `#broadcast_to`, however, instead of forwarding each method call one-for-one, we rely on the `#add` method which is expected of the logger interface. As such, we should not run into the kinds of bugs that affect `ActiveSupport::BroadcastLogger` when used alongside additional logger features such as tagged logging, such as rails/rails#49745. This enables customers to use both broadcast logging and tagged logging with the AppSignal logger without running into application-breaking bugs. As a trade-off, unlike `ActiveSupport::BroadcastLogger`, our broadcast implementation is sensitive to the order in which those additional features are applied, expecting them to be applied on top of the broadcast logger, and not on the underlying loggers: ```ruby # Incorrect example some_logger = ActiveSupport::TaggedLogging.new( Logger.new("/etc/app.log") ) appsignal_logger = Appsignal::Logger.new("app") # Even if `some_logger` is a tagging-enabled logger, # this logger will not behave as a tagging-enabled logger. Rails.logger = appsignal_logger.broadcast_to(some_logger) ``` ```ruby # Correct example some_logger = Logger.new("/etc/app.log") appsignal_logger = Appsignal::Logger.new("app") appsignal_logger.broadcast_to(some_logger) # As the tagged logging is applied on the broadcast logger, # both logs sent to AppSignal and to `some_logger` will include # given tags, and `Rails.logger` will be a tagging-enabled logger. Rails.logger = ActiveSupport::TaggedLogging.new(appsignal_logger) ```
- Loading branch information