Docs Menu

Docs HomeRealm

Logging - Swift SDK

On this page

  • Set or Change the Realm Log Level
  • Turn Off Logging
  • Customize the Logging Function

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.


See also:

This page shows how to set a Realm logger, which was added in Realm Swift SDK v10.39.0. This supersedes setting the Sync client log level in earlier versions of the Realm Swift SDK. For information on how to set the Sync client log level in an earlier version, refer to Set the Client Log Level - Swift SDK.

You can set the level of detail reported by the Realm Swift SDK. Set the log level for the default logger with Logger.shared.level:

Logger.shared.level = .trace

The RLMLogLevel enum represents the different levels of logging you can configure.

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.

// Set a log level that isn't too verbose
Logger.shared.level = .warn
// Later, when trying to debug something, change the log level for more verbosity
Logger.shared.level = .trace

The default log threshold level for the Realm Swift SDK is .info. This displays some information in the console. You can disable logging entirely by setting the log level to .off:

Logger.shared.level = .off

Initialize an instance of a Logger and define the function to use for logging.

// Create an instance of `Logger` and define the log function to invoke.
let logger = Logger(level: .detail) { level, message in
"REALM DEBUG: \( \(level) \(message) \n"


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 set a logger as the default logger for your app with Logger.shared. After you set the default logger, you can change the log level during the app lifecycle as needed.

let logger = Logger(level: .info) { level, message in
"REALM DEBUG: \( \(level) \(message) \n"
// Set a logger as the default
Logger.shared = logger
// After setting a default logger, you can change
// the log level at any point during the app lifecycle
Logger.shared.level = .debug
←  Test and Debug - Swift SDKApplication Services - Swift SDK →
Share Feedback
© 2023 MongoDB, Inc.


  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2023 MongoDB, Inc.