Allow for filtered logging using onRecord() #21454
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
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)
The text was updated successfully, but these errors were encountered: