New in version 1.8.0.
Puedes establecer o cambiar el nivel de registro de tu aplicación al desarrollar o depurar tu aplicación. Es posible que quieras cambiar el nivel de registro para registrar diferentes cantidades de datos dependiendo de tus necesidades de desarrollo.
Nota
This page shows how to set a Realm logger, which was added in Realm Kotlin SDK v1.8.0. This supersedes setting the Sync client log level in earlier versions of the Realm Kotlin SDK. For information on how to set the Sync client log level in an earlier version, refer to Set the Client Log Level - Kotlin SDK.
Set the Realm Log Level
Puede configurar el nivel de registro de su aplicación utilizando el global
Singleton deRealmLog. Puede configurar el RealmLog.level Propiedad a una entrada en la enumeración LogLevel para especificar el nivel de datos que desea recibir. Si la prioridad del nivel de registro es igual o superior a la definida RealmLog.level en, Realm registra el evento.
You can change the log level at any point during the app's lifecycle from this global singleton. 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.
// Set a log level using the global RealmLog singleton RealmLog.level = LogLevel.TRACE // Access your app and use realm val app: App = App.create(YOUR_APP_ID) // Replace this with your App ID val user = app.login(Credentials.emailPassword(email, password)) val config = SyncConfiguration.Builder(user, setOf(Toad::class)) .initialSubscriptions { realm -> add(realm.query<Toad>("name == $0", "name value"), "sync subscription") } .build() val realm = Realm.open(config) // You can change the log level at any point in your app's lifecycle as needed RealmLog.level = LogLevel.INFO
By default, all logs go to a default system logger that varies by system:
Android escribe registros en Logcat.
JVM logs to stdout.
MacOS logs to NSLog.
iOS logs to NSLog.
Tip
Para diagnosticar y solucionar errores locales en la aplicación, establezca el nivel de registro en debug o trace. Para implementaciones de producción, disminuye el nivel de registro para mejorar el rendimiento.
Establece un registrador personalizado
You can create a custom logger that implements the RealmLogger interface. You might want to customize logging to add specific tags or set specific log levels during development, testing, or debugging.
class MyLogger() : RealmLogger { override val tag: String = "CUSTOM_LOG_ENTRY" override val level: LogLevel = LogLevel.DEBUG override fun log( level: LogLevel, throwable: Throwable?, message: String?, vararg args: Any? ) { println(message) // Custom handling } }
A continuación, puedes inicializar tu logger personalizado y llamar a la función RealmLog.add() función para establecerlo como logger de tu aplicación.
You can also remove a specific logger or remove all loggers, including the system logger.
// Set an instance of a custom logger val myCustomLogger = MyLogger() RealmLog.add(myCustomLogger) // You can remove a specific logger RealmLog.remove(myCustomLogger) // Or remove all loggers, including the default system logger RealmLog.removeAll()