Logging - Flutter SDK
Changed in version v2.0.0.
You can set or change your app's log level when developing or debugging your application. You might want to change the log level to log different amounts of data depending on your development needs. You can specify different log levels or custom loggers on a per-isolate basis.
Tip
See also:
This page shows how to set a Realm logger. For information on how to set the Sync client log level in an earlier version, refer to Set the Client Log Level - Flutter SDK.
Set or Change the Realm Log Level
In the Flutter SDK, you can set the level of detail in different parts of your app. To configure the log level, pass a valid LogLevel value to setLogLevel.
// If no category is set, default is LogCategory.realm Realm.logger.setLogLevel(LogLevel.all, category: LogCategory.realm);
You can change the log level to increase or decrease verbosity at different points in your code. This behavior differs from the deprecated sync client log level, which had to be set before opening a synced realm and could not be changed.
Realm.logger.setLogLevel(LogLevel.off); await executeAppCode(); Realm.logger.setLogLevel(LogLevel.debug, category: LogCategory.realm); await executeComplexCodeToDebug();
Customize the Logger
The Flutter SDK logger conforms to the Dart Logger class.
To get started, set a log level:
Realm.logger.onRecord.listen((record) { // Do something with the log record print(record.message); });
Define custom logging behavior by listening to Realm.logger.onRecord:
Realm.logger.onRecord.listen((event) { // Do something with the log event - for example, print to console print("Realm log message: '$event'"); });
Turn Off Logging
You can turn off logging by passing LogLevel.off
to setLogLevel()
:
Realm.logger.setLogLevel(LogLevel.off);