Logging APIs in Mobile SDKs

Learn about the different logging APIs available in the Android (Kotlin) and iOS (Swift) SDKs.

This guide walks you through the logging APIs available in the RudderStack Android (Kotlin) and iOS (Swift) SDKs.

Overview

The RudderStack Android (Kotlin) and iOS (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 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 Android (Kotlin) and iOS (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 Android (Kotlin) and iOS (Swift) SDKs.

Android (Kotlin)

info

Instance-based logging in Android (Kotlin) SDK

Starting from v1.5.0, the Android (Kotlin) SDK only supports instance-based logging. You can configure the logger and logLevel directly on the Configuration object while initializing the SDK — this ties the logger to a specific Analytics instance, allowing different instances to use different loggers and log levels.

The older LoggerAnalytics singleton approach is deprecated in Android (Kotlin) SDK v1.5.0+, but will continue to work for backward compatibility.

Pass the logLevel parameter when creating the Configuration object:

via LoggerAnalytics (Deprecated)

warning
This method is deprecated but continues to work for backward compatibility. Use the instance-based logging approach instead.

iOS (Swift)

info
The iOS (Swift) SDK only supports the LoggerAnalytics singleton approach for logging.

The Android (Kotlin) and iOS (Swift) SDKs provide a way to print 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:

Android (Kotlin)

The Android (Kotlin) SDK supports the following ways for printing custom logs:

In a custom plugin

Use the logger extension property available in the Plugin interface — this gives you the logger tied to the Analytics instance that the plugin belongs to.

info

The logger is only accessible within a custom plugin via the Plugin.logger extension property. Direct access to analytics.logger outside of a plugin is not part of the public API.

You should access this property only after the plugin’s setup method has been invoked, as it depends on the plugin’s analytics property being initialized.

via LoggerAnalytics (Deprecated)

warning
This approach is deprecated but continues to work for backward compatibility. Use the logger extension property approach instead.

iOS (Swift)

Use a custom logger

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

Android (Kotlin)

For the Android (Kotlin) SDK, you can inherit the Logger interface to create a custom Logger class and then pass its instance to Configuration while initializing the SDK.

For example, follow these steps to use the Timber library to create a Logger class:

  1. Create a custom logger class:
  1. Pass the custom logger via Configuration:

iOS (Swift)

For the iOS (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? We're here to help.

Join the RudderStack Slack community or email us for support