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

Add onBefore callback #484

Open invipal opened 6 months ago

invipal commented 6 months ago

Hello,

Sometimes there can be different needs depending on the type of log or its source, or we might need to ignore them. For such situations, it would be very beneficial to be able to modify the log request before it's processed through a callback like onBefore, or to be able to completely ignore the log request.

For example;

Logger.root.onRecord = (event) {
    if (event.loggerName == 'xxx') {
      return event.copyWith(message: newFormat(event.message)); // format event message
    } else if (event.level == Level.WARNING) {
      return null; // ignore this record/event
    } else {
      return event;
   }
};