Logging APIs in Mobile SDKs

Learn about the different logging APIs available in the Kotlin and Swift SDKs.

This guide walks you through the logging APIs available in the Kotlin and Swift SDKs.

Overview

The RudderStack Kotlin and Swift SDKs provide a flexible and configurable logging mechanism that helps you:

  • Monitor and debug the SDK’s behavior.
  • Get fine-grained control over the amount of information to be recorded by leveraging multiple log levels.
  • Set up and use a custom logging mechanism and log your own messages by leveraging the SDK’s logging APIs.

Set the log level

You can define the log level using LoggerAnalytics by passing the value for the logLevel parameter. It controls the verbosity of the logs printed by the SDK and helps filter out logs based on their importance.

The Kotlin and Swift SDKs support the following log levels:

Log levelDescription
VERBOSELogs all the messages, including detailed internal operations. It is useful for deep debugging.
DEBUGLogs detailed information relevant for debugging and omits the additional internal logs.
INFOLogs general operational information about the SDK’s execution and helps track high-level flow.
WARNLogs potentially problematic situations that may not cause immediate failures. It is useful for detecting any unusual SDK behavior.
ERRORLogs only serious issues that impact the SDK’s functionality and require attention.
NONEDisables all logging. Use it when logging is unnecessary or needs to be disabled in production.

The following sections show you how to set a VERBOSE log level in the Kotlin and Swift SDKs.

Kotlin

Swift

Set custom logs

The Kotlin and Swift SDKs provide a LoggerAnalytics instance that you can use to set custom logs for the SDK. It is helpful when the SDK logs need to be printed in a custom plugin.

The SDKs provide the following methods for printing different levels of log messages:

Kotlin

Swift

Use a custom logger

You can create and use a custom logger that is used by the Kotlin and Swift SDKs to log messages — this is helpful in cases where you don’t want to rely on the SDK’s default logger.

Kotlin

For the Kotlin SDK, you can inherit the Logger interface to create a custom Logger class and then pass its instance to the setLogger API.

For example, follow these steps to use the Timber library for logging:

  1. Create a custom logger class:
  1. Add the custom logger class to LoggerAnalytics, as shown:

Swift

For the Swift SDK, you can inherit the Logger protocol to create a custom Logger class and then pass its instance to the setLogger API of LoggerAnalytics.

  1. Create a custom logger, as shown:
  1. Add MyCustomLogger to the LoggerAnalytics instance, as shown:

Questions? Contact us by email or on Slack