Skip to content

Commit

Permalink
Improved logging (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
kober32 authored May 9, 2024
1 parent 5dd1d53 commit 036160c
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 163 deletions.
5 changes: 5 additions & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.2.0 (May, 2024)

- Changed name of the log class to the `WDOLogger`
- Added listener to the log class

## 1.1.1 (Mar 6, 2024)

- Minor fixes
Expand Down
14 changes: 11 additions & 3 deletions docs/Logging.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Logging

The library is intensively logging into the console via `Logger`.
The library is intensively logging into the console via `WDOLogger`.

Possible log levels:

Expand All @@ -10,8 +10,16 @@ Possible log levels:
- `ERROR` - prints errors only
- `OFF` - logging is turned off

You can set the log level by `Logger.verboseLevel = Logger.VerboseLevel.OFF`.
You can set the log level by `WDOLogger.verboseLevel = WDOLogger.VerboseLevel.OFF`.

<!-- begin box info -->
`Logger` calls internally the `android.util.Log` class.
`WDOLogger` calls internally the `android.util.Log` class.
<!-- end -->

## Log Listener

The `WDOLogger` class offers a static `logListener` property. If you provide a listener, all logs will also be passed to it (the library always logs into the Android default log).

<!-- begin box info -->
Log listener comes in handy when you want to log into a file or some online service.
<!-- end -->
2 changes: 1 addition & 1 deletion library/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
# and limitations under the License.
#

VERSION_NAME=1.1.2-SNAPSHOT
VERSION_NAME=1.2.0-SNAPSHOT
GROUP_ID=com.wultra.android.digitalonboarding
ARTIFACT_ID=wultra-digital-onboarding
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package com.wultra.android.digitalonboarding

import android.content.Context
import android.os.Build
import com.wultra.android.digitalonboarding.log.WDOLogger
import com.wultra.android.digitalonboarding.networking.CustomerOnboardingApi
import com.wultra.android.digitalonboarding.networking.GetStatusResponse
import com.wultra.android.digitalonboarding.networking.OTPDetailResponse
Expand Down Expand Up @@ -108,7 +109,7 @@ class ActivationService(

init {
if (!canRestoreSession) {
D.warning("Created ActivationService without restoration.")
WDOLogger.w("Created ActivationService without restoration.")
processId = null
}
}
Expand All @@ -130,7 +131,7 @@ class ActivationService(
*/
fun status(callback: (ActivationResult<Status>) -> Unit) {

D.print("Retrieving the status")
WDOLogger.d("Retrieving the status")

val processId = guardProcessId(callback) ?: return

Expand All @@ -141,12 +142,12 @@ class ActivationService(
object : IApiCallResponseListener<GetStatusResponse> {
override fun onSuccess(result: GetStatusResponse) {
val success = Status.fromResponse(result)
D.print("Status call success: ${success.name}")
WDOLogger.i("Status call success: ${success.name}")
callback(ActivationResult.success(success))
}

override fun onFailure(error: ApiError) {
D.error(error)
WDOLogger.e(error)
callback(ActivationResult.failure(Fail(error)))
}
}
Expand All @@ -163,7 +164,7 @@ class ActivationService(
fun <T> start(credentials: T, callback: (ActivationResult<Unit>) -> Unit) {

if (processId != null) {
D.error("Activation can be started only when another activation is not in progress.")
WDOLogger.e("Activation can be started only when another activation is not in progress.")
callback(ActivationResult.failure(Fail(ApiError(ActivationInProgressException))))
return
}
Expand All @@ -175,12 +176,12 @@ class ActivationService(
object : IApiCallResponseListener<StartOnboardingResponse> {
override fun onSuccess(result: StartOnboardingResponse) {
processId = result.responseObject.processId
D.print("Start successful")
WDOLogger.i("Start successful")
callback(ActivationResult.success(Unit))
}

override fun onFailure(error: ApiError) {
D.error(error)
WDOLogger.e(error)
callback(ActivationResult.failure(Fail(error)))
}
}
Expand All @@ -204,17 +205,17 @@ class ActivationService(
object : IApiCallResponseListener<StatusResponse> {
override fun onSuccess(result: StatusResponse) {
this@ActivationService.processId = null
D.print("Cancel successful")
WDOLogger.i("Cancel successful")
callback(ActivationResult.success(Unit))
}

override fun onFailure(error: ApiError) {
if (forceCancel) {
this@ActivationService.processId = null
D.warning("Cancel failed, but forceCancel was used - returning success anyway.")
WDOLogger.w("Cancel failed, but forceCancel was used - returning success anyway.")
callback(ActivationResult.success(Unit))
} else {
D.error(error)
WDOLogger.e(error)
callback(ActivationResult.failure(Fail(error)))
}
}
Expand All @@ -225,7 +226,7 @@ class ActivationService(
/** Clears the stored data (without networking call). */
fun clear() {
processId = null
D.print("Clear successful")
WDOLogger.i("Clear successful")
}

/**
Expand All @@ -243,12 +244,12 @@ class ActivationService(
processId,
object : IApiCallResponseListener<StatusResponse> {
override fun onSuccess(result: StatusResponse) {
D.print("Clear successful")
WDOLogger.i("Clear successful")
callback(ActivationResult.success(Unit))
}

override fun onFailure(error: ApiError) {
D.error(error)
WDOLogger.e(error)
callback(ActivationResult.failure(Fail(error)))
}
}
Expand All @@ -258,7 +259,7 @@ class ActivationService(
fun createPowerAuthActivationData(otp: String): ActivationData? {
val processId = processId
if (processId == null) {
D.error("Cannot create activation data - process not started (missing processId).")
WDOLogger.e("Cannot create activation data - process not started (missing processId).")
return null
}
return ActivationDataWithOTP(processId, otp)
Expand All @@ -285,15 +286,15 @@ class ActivationService(
powerAuthSDK.createActivation(data, activationName) { result ->
result.onSuccess {
this.processId = null
D.print("PowerAuth activation created")
WDOLogger.i("PowerAuth activation created")
callback(ActivationResult.success(it))
}.onFailure {
// when no longer possible to retry activation
// reset the processID, because we cannot recover
if ((it as? FailedApiException)?.allowOnboardingOtpRetry() == false) {
this.processId = null
}
D.print("PowerAuth activation failed - $it")
WDOLogger.e("PowerAuth activation failed - $it")
callback(ActivationResult.failure(Fail(ApiError(it))))
}
}
Expand All @@ -303,7 +304,7 @@ class ActivationService(

val processId = this.processId
if (processId == null) {
D.error("ProcessId is required for the requested method but not available. This mean that the process was not started.")
WDOLogger.e("ProcessId is required for the requested method but not available. This mean that the process was not started.")
callback(WDOResult.failure(Fail(ApiError(ActivationNotRunningException))))
return null
}
Expand All @@ -313,7 +314,7 @@ class ActivationService(
private fun <T>verifyCanStartProcess(callback: (ActivationResult<T>) -> Unit): Boolean {

if (!powerAuthSDK.canStartActivation()) {
D.error("Cannot start the activation: PowerAuthSDK.canStartActivation() == false")
WDOLogger.e("Cannot start the activation: PowerAuthSDK.canStartActivation() == false")
processId = null
callback(ActivationResult.failure(Fail(ApiError(CannotActivateException))))
return false
Expand All @@ -334,12 +335,12 @@ class ActivationService(
processId,
object : IApiCallResponseListener<OTPDetailResponse> {
override fun onSuccess(result: OTPDetailResponse) {
D.print("Get OTP successful")
WDOLogger.i("Get OTP successful")
callback(ActivationResult.success(result.responseObject.otpCode))
}

override fun onFailure(error: ApiError) {
D.error(error)
WDOLogger.e(error)
callback(ActivationResult.failure(Fail(error)))
}
}
Expand Down

This file was deleted.

Loading

0 comments on commit 036160c

Please sign in to comment.