Docs Menu
Docs Home
/ /
Atlas Device SDKs
/
/

Set the Client Log Level - Kotlin SDK

On this page

  • Set the Sync Log Level
  • Set a Custom Logger

Changed in version 1.8.0: Deprecated in favor of Realm Logger

Warning

This page shows how to set a Sync client log level in Realm Kotlin SDK versions 1.7.1 and earlier. Realm Kotlin SDK v1.8.0 supersedes this logging implementation with a Realm logger you can set and configure. For information on how to set a Realm logger in a later version, refer to Logging - Kotlin SDK.

You can set the Device Sync client log level on the SyncConfiguration instance on your App. You might want to do this to log different amounts of data depending on the app's environment.

To configure the log level, set the RealmLogger.level property to one of the logger levels provided by LogLevel.

See the LogLevel documentation for a description of each available log level. Note that more logging can negatively affect performance.

You must set the log level before you open a synced realm.

// Access your app
val app = App.create(YOUR_APP_ID)
val user = app.login(credentials)
// Access the configuration builder for the app
val config = SyncConfiguration.Builder(user, setOf(Toad::class))
// Set the logger to provide debug log
// Must be set BEFORE you open a synced realm
.log(LogLevel.DEBUG)
.initialSubscriptions { realm ->
add(realm.query<Toad>(), "sync subscription")
}
.build()
// Open the synced realm
// Synced realm writes logs according to the log level set above
val realm = Realm.open(config)

Tip

To diagnose and troubleshoot errors while developing your application, set the log level to debug or trace. For production deployments, decrease the log level for improved performance.

You can pipe Device Sync logs to a custom RealmLogger object by setting the customLoggers parameter on the SyncConfiguration builder. If you don't specify this parameter, the Kotlin SDK outputs log strings to the default system logger (LogCat on Android, NSLog on iOS).

You must set the custom logger before you open a synced realm.

val customLogger = CustomLogger()
customLogger.tag = "Engineering debugging"
customLogger.message = "${customLogger.logLevel}: ${customLogger.message}"
// Access your app
val app = App.create(YOUR_APP_ID)
val user = app.login(credentials)
// Access the configuration builder for the app
val config = SyncConfiguration.Builder(user, setOf(Toad::class))
// Set the custom logger and applicable log level
// Must be set BEFORE you open a synced realm
.log(LogLevel.ALL, customLoggers = listOf(customLogger))
.initialSubscriptions { realm ->
add(realm.query<Toad>(), "sync subscription")
}
.build()
// Open the synced realm with the custom logger
val realm = Realm.open(config)
← 
 →