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

Allow for filtered logging using onRecord() #21454

Closed
DartBot opened this issue Oct 29, 2014 · 3 comments
Closed

Allow for filtered logging using onRecord() #21454

DartBot opened this issue Oct 29, 2014 · 3 comments
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Oct 29, 2014

This issue was originally filed by @stevenroose


The Logger class from the logging package has an onRecord getter that gives the stream of logrecords. However, often users want only logs from a certain level and up. Currently that is possible by doing the filtering yourself like this:

  myLogger.onRecord.where((LogRecord logRecord) => logRecord.level >= filterLevel).listen(loggerHandler);

Java's java.util.logging has filtered handlers built in to make this easy, but Dart does not.

I suggest to change the onRecord getter to a method that allows you to specify a level on which to filter records]. It works like this:

  myLogger.onRecord(filterLevel).listen(loggerHandler);

In attachment is a patch with this change and the required changes to the unit tests.

I know this is a breaking change, so it requires a new version. An alternative might be to introduce an additional method for this change, but I think using onRecord for this purpose is more suitable.


Attachment:
logging-filtering.diff (4.97 KB)

@DartBot
Copy link
Author

DartBot commented Oct 29, 2014

This comment was originally written by @stevenroose


An alternative solution would be to let onRecord return a FilterableLogRecordStream that extends Stream but also has a getter for each loglevel, so that it would look like this:

  myLogger.onRecord.filter(Level.WARNING).listen(loggerHandler);

or

  myLogger.onRecord.warning.listen(loggerHandler);

I added implementation for this change as a patch.


Attachment:
logging-filteredstream.diff (4.86 KB)

@iposva-google
Copy link
Contributor

Added Pkg-Logging, Area-Pkg, Triaged labels.

@DartBot DartBot added Type-Enhancement area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. labels Oct 30, 2014
@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

This issue has been moved to dart-lang/logging#21.

@DartBot DartBot closed this as completed Jun 5, 2015
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed triaged labels Mar 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants