Repository navigation
Commit f9a7dc7
authored
Make setLoggingLevel and disableLogging work without app setup (#1288)
## Problem
`setLoggingLevel()` and `disableLogging()` throw in an app that has not
set up `package:logging` in a particular way:
```
Unsupported operation: Please set "hierarchicalLoggingEnabled" to true if you want to change the level on a non-root logger.
```
## Cause
Both functions set a level on the SDK's own logger, `Logger('livekit')`.
`package:logging` has two modes. In the default one only the root logger
has a level, every other logger follows it, and setting a level on
another logger is an error, because it would never be consulted. A
logger gets a level of its own only once `hierarchicalLoggingEnabled` is
on.
The SDK never turned that on. So the functions have thrown since they
were added in #244, unless the app had turned it on for its own reasons.
Every `logging` release the SDK has allowed since then (1.0.0 to 1.3.0)
behaves this way.
## Fix
Both functions turn `hierarchicalLoggingEnabled` on before they set the
level. It is a process-wide switch, and turning it on changes nothing
for code that does not use it:
- A logger without a level of its own keeps following `Logger.root`.
- SDK records still reach `Logger.root.onRecord`. In this mode a record
goes to its logger and to every parent.
No signature changes. The README gets a short Logging section, it had
none.
## Testing
New `test/logger_test.dart`, six tests that start from an app that has
set up nothing. All six fail without the fix.
- neither function throws
- with the SDK at FINE and the root at INFO, an SDK record at FINE
reaches a root listener, and one at FINEST does not
- another logger stays on the root level
- `disableLogging()` silences the SDK and nothing else
- a level can be set again after logging was disabled
Full suite: 580 passed, 1 skipped. Analyze, format, import order and the
version check pass.
## Notes
- Found while writing an e2e-flutter scenario that needed the SDK at its
most verbose level.
- One difference in hierarchical mode: `onRecord` on a logger other than
the root one delivers that logger's records only. In the default mode it
delivers everything, because it is the root stream. An app that listens
on `Logger.root.onRecord`, which is what the README now shows, sees no
difference.
- Not needed for 2.14.0. The functions fail the same way in every
published release.1 parent 5e490e3 commit f9a7dc7
4 files changed
Lines changed: 123 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
609 | 609 | | |
610 | 610 | | |
611 | 611 | | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
612 | 633 | | |
613 | 634 | | |
614 | 635 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
33 | 37 | | |
| 38 | + | |
34 | 39 | | |
35 | 40 | | |
36 | 41 | | |
37 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
38 | 49 | | |
| 50 | + | |
39 | 51 | | |
40 | 52 | | |
41 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
0 commit comments