Created
July 8, 2020 09:57
-
-
Save yrom/1a86a6995720d9a4ff9261617fb13783 to your computer and use it in GitHub Desktop.
Flutter logging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:logging/logging.dart'; | |
import 'dart:developer' as developer; | |
void initLogging() { | |
// disable hierarchical logger | |
hierarchicalLoggingEnabled = false; | |
// change to another level as needed. | |
Logger.root.level = Level.INFO; | |
// skip logging stactrace below the SEVERE level. | |
recordStackTraceAtLevel = Level.SEVERE; | |
assert(() { | |
recordStackTraceAtLevel = Level.WARNING; | |
// print all logs on debug build. | |
Logger.root.level = Level.ALL; | |
return true; | |
}()); | |
Logger.root.onRecord.listen((event) { | |
developer.log( | |
event.message, | |
time: event.time, | |
sequenceNumber: event.sequenceNumber, | |
level: event.level.value, | |
name: event.loggerName, | |
zone: event.zone, | |
error: event.error, | |
stackTrace: event.stackTrace, | |
); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment