Skip to content

Commit

Permalink
[go_router] Don't clear listeners when logging is disabled (#2533)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpryan committed Sep 8, 2022
1 parent ba51afa commit ba3a520
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
4 changes: 4 additions & 0 deletions packages/go_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.4.1

- Fix an issue where disabling logging clears the root logger's listeners

## 4.4.0

- Adds `buildPageWithState` to `GoRouteData`.
Expand Down
1 change: 0 additions & 1 deletion packages/go_router/lib/src/logging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ StreamSubscription<LogRecord>? _subscription;
void setLogging({bool enabled = false}) {
_subscription?.cancel();
if (!enabled) {
log.clearListeners();
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/go_router/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: go_router
description: A declarative router for Flutter based on Navigation 2 supporting
deep linking, data-driven routes and more
version: 4.4.0
version: 4.4.1
repository: https://github.com/flutter/packages/tree/main/packages/go_router
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22

Expand Down
16 changes: 3 additions & 13 deletions packages/go_router/test/logging_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,11 @@ import 'package:go_router/src/logging.dart';
import 'package:logging/logging.dart';

void main() {
// Reset the logger before each test.
setUp(() {
setLogging();
});
test('setLogging enables log messages on the logger', () {
log.onRecord.listen(expectAsync1<void, LogRecord>((LogRecord r) {}));

test('setLogging does not clear listeners', () {
log.onRecord
.listen(expectAsync1<void, LogRecord>((LogRecord r) {}, count: 2));
setLogging(enabled: true);
log.info('message');
});

test('setLogging disables log messages on the logger', () {
log.onRecord
.listen(expectAsync1<void, LogRecord>((LogRecord r) {}, count: 0));

setLogging();
log.info('message');
});
Expand Down

0 comments on commit ba3a520

Please sign in to comment.