Clone to keep extended Logger methods for tagged logger#40759
Clone to keep extended Logger methods for tagged logger#40759rafaelfranca merged 1 commit intorails:masterfrom orhantoy:broadcast-tagged-logging
Conversation
`#dup` resets the extended Logger methods that could come from enabling broadcasting. That would mean if we create a tagged logger from a Logger with broadcasting enabled (usually to stdout), the new tagged logger will not perform broadcasting.
Clone to keep extended Logger methods for tagged logger
|
This does sound like a sensible change, though it does break broadcasting to multiple loggers with different formatters. In Rails 6 this used to work: logger = ActiveSupport::TaggedLogging.new(Logger.new "base.log")
logger2 = Logger.new("fancy.log"); logger2.formatter = proc{|_,_,_,msg| "*** #{msg} ***" }
logger.extend(ActiveSupport::Logger.broadcast(logger2))
logger.info "Hello"this would write "Hello" to base.log, and "*** Hello ***" to fancy.log. In Rails 7, if you call |
|
There is no reason to break that behavior. Can you try to fix and open a PR? It seems we just need to copy the formatter from the original logger. |
|
@rafaelfranca will do. |
Summary
#dupresets the extended Logger methods that could come from enabling broadcasting. That would mean if we create a tagged logger from a Logger with broadcasting enabled (usually to stdout), the new tagged logger will not perform broadcasting.Other Information
I'm not sure if the current behavior is as expected, but it seemed surprising to me. If your Logger has broadcasting enabled, it feels like the derived tagged loggers should also broadcast. Happy to hear what you think.
Relates to #27792 and #38850