Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger listeners unexpectedly fire with lower levels #481

Open
craiglabenz opened this issue Jul 9, 2023 · 1 comment
Open

Logger listeners unexpectedly fire with lower levels #481

craiglabenz opened this issue Jul 9, 2023 · 1 comment

Comments

@craiglabenz
Copy link
Contributor

Is the following behavior expected?

Consider a root logger that filters on Level.WARNING with a child logger that filters on Level.FINE, but has no listeners.

Once the child logger accepts a message, it propagates up to the root logger and prints, despite being a lower level than the root logger's configuration.

import 'package:logging/logging.dart';

void main() {
  hierarchicalLoggingEnabled = true;
  Logger.root.level = Level.WARNING;
  Logger.root.onRecord.listen((record) {
    print('WARNING ONLY: ${record.message}');
  });

  final fineLogger = Logger('FINE LOGGER');
  fineLogger.level = Level.FINE;
  fineLogger.fine('FINE');
}

results in

$ dart logging_test.dart
WARNING ONLY: FINE

Of course, adjusting the root logger's handler to be like so can solve this problem:

  Logger.root.onRecord.listen((record) {
    if (record.level < Logger.root.level) return;
    print('WARNING ONLY: ${record.message}');
  });

But this feels redundant.

Is the original behavior expected?

@craiglabenz
Copy link
Contributor Author

Discovered while adding documentation requested in #477.

@mosuem mosuem transferred this issue from dart-archive/logging Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants