Skip to content

[go_router] Turn off logging#2222

Merged
johnpryan merged 11 commits into
flutter:mainfrom
johnpryan:turn-off-logging
Jun 24, 2022
Merged

[go_router] Turn off logging#2222
johnpryan merged 11 commits into
flutter:mainfrom
johnpryan:turn-off-logging

Conversation

@johnpryan

@johnpryan johnpryan commented Jun 7, 2022

Copy link
Copy Markdown
Contributor

Clear listeners when setLogging is false

fixes flutter/flutter#99115

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@johnpryan johnpryan changed the title Turn off logging [go_router] Turn off logging Jun 7, 2022
@johnpryan johnpryan changed the title [go_router] Turn off logging [go_router] test-exempt: Turn off logging Jun 7, 2022
@johnpryan johnpryan changed the title [go_router] test-exempt: Turn off logging [go_router] Turn off logging Jun 7, 2022
@stuartmorgan-g stuartmorgan-g requested a review from chunhtai June 14, 2022 20:05
@johnpryan johnpryan requested review from loic-sharma and removed request for chunhtai June 21, 2022 16:58
import 'package:go_router/src/logging.dart';
import 'package:logging/logging.dart';

void main() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it'd be worthwhile to do a higher level test, like a test app that uses GoRouter that would log on v4.0.0?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could test the behavior where specifying debugLogDiagnostics calls setLogging with the correct value. We could also validate the log output itself, but that might be overkill.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If logging is disabled, would there be 0 logs? If yes, we could test for the absence of logs instead of validating log messages directly. If no, feel free to skip as checking whether setLogging was called with the correct value is perfectly reasonable.

@loic-sharma loic-sharma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but perhaps consider adding a higher level test.

description: A declarative router for Flutter based on Navigation 2 supporting
deep linking, data-driven routes and more
version: 4.0.0
version: 4.0.1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this change include an update to the release notes?

@ycherniavskyi

Copy link
Copy Markdown
Contributor

What is about such test? As for me it also must pass, but with current implementation it is not, because we clear listeners on setLogging, but not disable logging as it.

  test('setLogging disables log messages on the logger', () {
     setLogging(enabled: false);

     log.onRecord
         .listen(expectAsync1<void, LogRecord>((LogRecord r) {}, count: 0));

     log.info('message');
   });

@johnpryan

Copy link
Copy Markdown
Contributor Author

@ycherniavskyi I'm not sure I understand your question. Are you having an issue in your app or while running tests?

@ycherniavskyi

Copy link
Copy Markdown
Contributor

@johnpryan, not exactly. Provided test snipped shows that the current setLogging implementation does not turn off logging permanently. It just cleared existing listeners (which actually has a side effect if logging is used without hierarchicalLoggingEnabled), but new listeners will receive go_router logging.

Here is provided test snipped error output:

Callback called more times than expected (0).
dart:async                              _BroadcastStreamController.add
package:logging/src/logger.dart 276:51  Logger._publish
package:logging/src/logger.dart 200:14  Logger.log
package:logging/src/logger.dart 244:7   Logger.info
test/logging_test.dart 33:9             main.<fn>
===== asynchronous gap ===========================
dart:async                              _StreamImpl.listen
test/logging_test.dart 31:18            main.<fn>

✖ setLogging disables log messages on the logger permanently
Exited (1)

@johnpryan johnpryan deleted the turn-off-logging branch July 22, 2022 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[go_router] Unable to turn off logging

3 participants