Flutter extension for the logging package.
This package provides a simple tool for logging messages in your applications and a set of additional utilities.
Flogger.d/i/w/e send messages through Dart's logging package. Flogger listeners receive a FloggerRecord, which can be printed or forwarded to another service. The in-app LogConsole has its own buffer: register a listener that calls LogConsole.add to populate it.
Version 4.0 requires Dart 3.12 and Flutter 3.47 or newer, and declares Android and iOS support. See the migration guide when upgrading from 3.x.
- Print logs to the console using a standard format.
- Send logs to 3rd party services (ie: Crashlytics, DataDog, etc.)
- Print class and method names where the log was triggered.
- View and share all logs from inside the app.
- Capture and format logging logs from 3rd party packages.
Use the Flogger static class to access all logging methods.
-
Initialize the logger.
Flogger.init();
-
Register a listener to print logs to the developer console.
if (kDebugMode) { Flogger.registerListener( (record) => log(record.printable(), stackTrace: record.stackTrace), ); }
registerListenerreturns aFloggerListenerRegistration. Keep it and callawait registration.cancel()when a listener belongs to a shorter-lived component.Flogger.clearListeners()cancels only listeners registered throughFlogger.Flogger.initsetsLogger.root.leveltoLevel.ALLorLevel.INFOaccording toshowDebugLogs, so the setting also affects logs from other packages usinglogging.
Log messages with their severity using the following methods:
Flogger.d("Debug message");
Flogger.i("Info message");
Flogger.w("Warning message");
Flogger.e("Error message");FloggerRecord.message contains the unformatted message. record.printable() applies the configured prefix, timestamp, and custom printer.
These calls will result in the logs below when using the default configuration:
[log] D/App SampleClass: Debug message
[log] I/App SampleClass: Info message
[log] W/App SampleClass: Warning message
[log] E/App SampleClass: Error messageUse FloggerConfig to choose the logger name, caller names, timestamps, debug filtering, or a custom printer:
Flogger.init(
config: const FloggerConfig(
loggerName: 'App',
printClassName: true,
printMethodName: false,
showDateTime: false,
showDebugLogs: true,
),
);Set printer to a FloggerPrinter for a custom display string; it overrides the other print options.
Use the LogConsole class to view your logs inside the app.
-
Add logs to the console buffer by registering a new listener.
Flogger.registerListener( (record) => LogConsole.add( OutputEvent(record.level, [record.printable()]), bufferSize: 1000, // Remember the last X logs ), );
-
Open the logs console to view all recorded logs.
LogConsole.open(context);
The console updates while it is open. Search and severity filters apply to the displayed list and to Copy; copied text includes every matching row in its original case. LogConsole.clear() removes buffered logs. bufferSize must be positive and defaults to 1000.
Use the loggerName parameter when adding logs to print them as a different logger. This can be useful for differentiating calls made from the different layers in your app. For example:
Flogger.i("Info message", loggerName: "Network");
Flogger.w("Warning message", loggerName: "Database");Register additional listeners to send logs to different services, for example:
if (kReleaseMode) {
Flogger.registerListener((record) {
// Filter logs that may contain sensitive data
if(record.loggerName != "App") return;
if(record.message.contains("apiKey")) return;
if(record.message.contains("password")) return;
// Log to 3rd party services
FirebaseCrashlytics.instance.log(record.printable());
DatadogSdk.instance.logs?.info(record.printable());
});
}Contributions are most welcome! Feel free to open a new issue or pull request to make this project better.
- Set the new version on the pubspec.yaml
versionfield. - Update the CHANGELOG.md file documenting the changes.
- Update the README.md file if necessary.
- Run
fvm flutter pub get,fvm dart format --output=none --set-exit-if-changed lib test,fvm flutter analyze, andfvm flutter test. - Analyze and build the example's Android and iOS debug apps, and check an app using a local path dependency.
- Run
fvm flutter pub publish --dry-runand review the files and warnings. - Publish with
fvm flutter pub publishafter the release PRs are merged. - Tag the published commit and create a GitHub release using the CHANGELOG.md entry.
- Logging - Copyright (c) 2013 the Dart project authors BSD 3-Clause for providing the logging framework this library depends on.
- Logger Flutter - Copyright (c) 2019 Simon Leier MIT License for creating the log console.
This repo is covered under the MIT License.

