Orchestration SDKs

Customizing logging on Android

PingOne Advanced Identity Cloud PingAM Android

When you develop applications with the Orchestration SDK, you might need to understand its internal workings or troubleshoot unexpected behavior.

Use logging to gain crucial insights into your application’s operations, identify issues, verify expected functionality, and better understand authentication flows.

This section covers how to configure and customize the logging output from the Orchestration SDK for Android.

Configuring Android Logcat logging

To configure the logging output from the Orchestration SDK for Android, specify the logger to use in the client module configuration:

Setting the logging level in the journey client configuration
import com.pingidentity.logger.Logger

val journey = Journey {
  logger = Logger.STANDARD
  serverUrl = "https://openam-forgerock-sdks.forgeblocks.com/am"
  realm = "alpha"
  cookie = "ch15fefc5407912"
}

The Orchestration SDK for Android includes the following logger presets:

Logger preset Description

STANDARD

Outputs all log messages to the Android Logcat.

WARN

Outputs only warning and error log messages to the Android Logcat.

NONE

Prevents all log messages.

The STANDARD logger tags messages in Android Logcat with the Orchestration SDK version. You can filter the console to only show the tagged messages:

Filtering Android Logcat output by tag, role=
Figure 1. Filtering Android Logcat output by tag

Defining and using custom loggers

In addition to the preset loggers you can create your own loggers. For example, you could output Orchestration SDK for Android messages to a file or a third-party service, or filter which messages to display.

Step 1. Installing modules

To create custom loggers, you need to add the Logger module for Android as a dependency to your project:

  • logging

To install the module into your Android app:

  1. In the Project tree view of your Android Studio project, open the build.gradle.kts file.

  2. In the dependencies section, add the logger module as a dependency:

    dependencies {
      implementation("com.pingidentity.sdks:logger:2.0.0")
    }

Remember to synchronize your Gradle project after adding dependencies.

Step 2. Defining and using custom loggers

To create a custom logger, first define a class and override each of the logger methods with the new behavior.

For example, the following code creates a custom logger named WARN_ERROR_ONLY, that only outputs warning and error messages, and ignores both info and debug messages:

Defining a custom logger class on Android
import com.pingidentity.logger.Logger.Companion.logger

open class WarnErrorOnlyLogger : Logger {

    override fun d(message: String) {
    }

    override fun i(message: String) {
    }

    override fun w(message: String, throwable: Throwable?) {
        println("$message: $throwable")
    }

    override fun e(message: String, throwable: Throwable?) {
        println("$message: $throwable")
    }
}

val Logger.Companion.WARN_ERROR_ONLY: Logger by lazy {
    WarnErrorOnlyLogger()
}

To use the custom logger in your app, specify the logger’s name, just as with the preset loggers:

Using a custom logger on Android
val journey = Journey {
  logger = WARN_ERROR_ONLY
  serverUrl = "https://openam-forgerock-sdks.forgeblocks.com/am"
  realm = "alpha"
  cookie = "ch15fefc5407912"
}