Skip to content

Instantly share code, notes, and snippets.

@yrom
Created July 8, 2020 09:57
Show Gist options
  • Save yrom/1a86a6995720d9a4ff9261617fb13783 to your computer and use it in GitHub Desktop.
Save yrom/1a86a6995720d9a4ff9261617fb13783 to your computer and use it in GitHub Desktop.
Flutter logging
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