Learn about the different logging APIs available in the Kotlin SDK.
3 minute read
This guide walks you through the logging APIs available in the Kotlin SDK.
Overview
The Kotlin SDK provides 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 SDK supports the following log levels:
Log level
Description
VERBOSE
Logs all the messages, including detailed internal operations. It is useful for deep debugging.
DEBUG
Logs detailed information relevant for debugging and omits the additional internal logs.
INFO
Logs general operational information about the SDK’s execution and helps track high-level flow.
WARN
Logs potentially problematic situations that may not cause immediate failures. It is useful for detecting any unusual SDK behavior.
ERROR
Logs only serious issues that impact the SDK’s functionality and require attention.
NONE
Disables all logging. Use it when logging is unnecessary or needs to be disabled in production.
The following snippet shows you how to set a VERBOSE log level:
The Kotlin SDK provides 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 SDK provides the following methods for printing different levels of log messages:
// Verbose log message
LoggerAnalytics.verbose("This is a verbose log message providing detailed internal information.")// Debug log message
LoggerAnalytics.debug("Debugging info: API request started.")// Info log message
LoggerAnalytics.info("SDK initialized successfully.")// Warn log message
LoggerAnalytics.warn("Low memory warning detected.")// Error log message
LoggerAnalytics.error("Failed to fetch user data: Network error.")
// Verbose log message
LoggerAnalytics.INSTANCE.verbose("This is a verbose log message providing detailed internal information.")// Debug log message
LoggerAnalytics.INSTANCE.verbose("Debugging info: API request started.")// Info log message
LoggerAnalytics.INSTANCE.verbose("SDK initialized successfully.")// Warn log message
LoggerAnalytics.INSTANCE.verbose("Low memory warning detected.")// Error log message
LoggerAnalytics.INSTANCE.verbose("Failed to fetch user data: Network error.")
Use a custom logger
You can create and use a custom logger that is used by the SDK to log messages—this is helpful in cases where you don’t want to rely on the SDK’s default logger.
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:
This site uses cookies to improve your experience while you navigate through the website. Out of
these
cookies, the cookies that are categorized as necessary are stored on your browser as they are as
essential
for the working of basic functionalities of the website. We also use third-party cookies that
help
us
analyze and understand how you use this website. These cookies will be stored in your browser
only
with
your
consent. You also have the option to opt-out of these cookies. But opting out of some of these
cookies
may
have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This
category only includes cookies that ensures basic functionalities and security
features of the website. These cookies do not store any personal information.
This site uses cookies to improve your experience. If you want to
learn more about cookies and why we use them, visit our cookie
policy. We'll assume you're ok with this, but you can opt-out if you wish Cookie Settings.