dart-lang / core

This repository is home to core Dart packages.
https://pub.dev/publishers/dart.dev
BSD 3-Clause "New" or "Revised" License
19 stars 7 forks source link

Logger.detached does not fire onRecord messages #434

Closed matanlurey closed 4 years ago

matanlurey commented 7 years ago

It would be nice to document how to catch messages :-/

java-james commented 5 years ago

This is related to hierarchicalLoggingEnabled. If the detached logger isn't a child of the root logger and hierarchicalLoggingEnabled = false then it will never reach the detached logger. Which can be a little confusing.

For example this logger cannot log: final logger = Logger.detached('DetachedLogger')..level = Level.ALL..onRecord.listen((rec) { print('${rec.level.name}: ${rec.time}: ${rec.message}'); }); logger.info('test');

Error comes from logger.dart line 183 trying to use the root logger (which has a null controller) if hierarchicalLoggingEnabled is false

jamesderlin commented 4 years ago

Why is this closed?

  1. I don't see any documentation for Logger.detached that explains this. Logger.detached purports to be "not a part of the global hierarchical loggers structure", so it doesn't make sense to me that it should be affected by hierarchicalLoggingEnabled.
  2. I'm confused what purpose Logger.detached has if it requires hierarchicalLoggingEnabled = true. That defeats the point of why I want to use Logger.detached.
jamesderlin commented 4 years ago

Maybe @astashov can comment on the intent of how Logger.detached is supposed to be used.

Anyway, if we can agree that this should be fixed, I could take it on. I think the level getter and setter also should be adjusted.