Bug when broadcasting TaggedLogging(without a block) loggers.
Steps to reproduce
require 'active_support'
main_logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new('main_logger.log'))
broadcast_logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new('broadcast_logger.log'))
main_logger.extend(ActiveSupport::Logger.broadcast(broadcast_logger))
main_logger.tagged('tag')
main_logger.info('text')
Expected behavior
$ tail main_logger.log broadcast_logger.log
==> main_logger.log <==
# Logfile created on 2022-08-19 18:53:04 +0900 by logger.rb/v1.5.0
text
==> broadcast_logger.log <==
# Logfile created on 2022-08-19 18:53:04 +0900 by logger.rb/v1.5.0
text
Actual behavior
$ tail main_logger.log broadcast_logger.log
==> main_logger.log <==
# Logfile created on 2022-08-19 18:53:04 +0900 by logger.rb/v1.5.0
text
==> broadcast_logger.log <==
# Logfile created on 2022-08-19 18:53:04 +0900 by logger.rb/v1.5.0
[tag] text
If #tagged
is used without blocking, the tag is incorrectly referenced in the broadcast destination logger.
I think it is a bug related to https://github.com/rails/rails/pull/44695.
When the formatter of the logger that originated the broadcast is updated, the reference to the tag to which the broadcast is directed is switched. https://github.com/rails/rails/blob/04972d9b9ef60796dc8f0917817b5392d61fcf09/activesupport/lib/active_support/tagged_logging.rb#L99-L107
without block #tagged
creates a temporary logger, in which case the formatter is updated.
https://github.com/rails/rails/blob/04972d9b9ef60796dc8f0917817b5392d61fcf09/activesupport/lib/active_support/tagged_logging.rb#L116
https://github.com/rails/rails/blob/04972d9b9ef60796dc8f0917817b5392d61fcf09/activesupport/lib/active_support/tagged_logging.rb#L85-L90
As a result, it appears that tags applied to temporary loggers are subsequently referenced in the broadcast destination loggers.
supplementary information
The standard output of logs at rails server startup in the development environment is implemented in broadcast.
Therefore, there may be differences in log output between standard output and log/develooment.log
.
https://github.com/rails/rails/blob/3d84e1298b8dd073fb8be0725f8112f9bbdab51a/railties/lib/rails/commands/server/server_command.rb#L75-L85
System configuration
Rails version: 7.0.2.3
Ruby version: 3.1.1