Customizing logging on Android
PingOne 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:
import com.pingidentity.logger.Logger
val daVinci = DaVinci {
logger = Logger.STANDARD
module(Oidc) {
clientId = "6c7eb89a-66e9-ab12-cd34-eeaf795650b2"
discoveryEndpoint = "https://auth.pingone.com/3072206d-c6ce-ch15-m0nd-f87e972c7cc3/as/.well-known/openid-configuration"
scopes = mutableSetOf("openid", "profile", "email", "address", "revoke")
redirectUri = "com.example.demo://oauth2redirect"
}
}
The Orchestration SDK for Android includes the following logger presets:
| Logger preset | Description |
|---|---|
|
Outputs all log messages to the Android Logcat. |
|
Outputs only warning and error log messages to the Android Logcat. |
|
Prevents all log messages. |
|
The
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:
-
In the Project tree view of your Android Studio project, open the
build.gradle.ktsfile. -
In the
dependenciessection, add theloggermodule 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:
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:
val daVinci = DaVinci {
logger = WARN_ERROR_ONLY
module(Oidc) {
clientId = "6c7eb89a-66e9-ab12-cd34-eeaf795650b2"
discoveryEndpoint = "https://auth.pingone.com/3072206d-c6ce-ch15-m0nd-f87e972c7cc3/as/.well-known/openid-configuration"
scopes = mutableSetOf("openid", "profile", "email", "address", "revoke")
redirectUri = "com.example.demo://oauth2redirect"
}
}