You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BroadcastLogger should support TaggedLogging correctly.
[Fixes#49745#52876]
[Related #51883#49771]
This commit extends BroadcastLogger when TaggedLogging is loaded in
order to ensure that BroadcastLogger#tagged behaves as expected when
there are multiple loggers being broadcast to.
TaggedLogging provides two related, but distinct interfaces:
1. Calling `logger.tagged(*tags)` without a block returns a new Logger
with the provided tags pushed to its tag stack.
2. Calling `logger.tagged(*tags) { |logger| ... }` with a block pushes
the tags to the existing Logger and yields the logger to block.
Previously, BroadcastLogger would only function as expected if there
was just one Logger being broadcast to. When there were multiple
loggers: when calling `tagged` with a block, it would yield a block
multiple times, once for each logger; when called without a block, it
would call `tagged` on each logger and return an Array of the results.
This inconsistent behaviour has caused issues such as those referenced
above. In development environments in particular, logger configuration
can often result in a BroadcastLogger with two loggers, since the
`bin/rails server` command will always broadcast to STDOUT, resulting
in confusing behaviour.
This commit provides a `BroadcastLogger#tagged` implementation that,
for the non-block form returns a new BroadcastLogger broadcasting to
the new tagged Loggers, and for the block-form, it 'wraps' the
user-provided block within nested calls to `TaggedLogging#logged`.
The user-provided block is only executed in the innermost call.
For example:
```ruby
# BroadcastLogger with two Loggers being broadcasted to
broadcaster.tagged("FOO") { |logger|
...
}
```
Would execute similarly to:
```ruby
broadcasts[0].tagged("FOO") {
broadcasts[1].tagged("FOO") {
yield(broadcaster)
}
}
```
0 commit comments