From 3cc9a207e55ea0dc651ff563cc4f9572ba8f8f30 Mon Sep 17 00:00:00 2001 From: Jan Kobersky <5406945+kober32@users.noreply.github.com> Date: Fri, 17 May 2024 10:33:45 +0200 Subject: [PATCH] Log improvements (#144) --- .github/workflows/build.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/tests.yml | 7 +- docs/Changelog.md | 5 + docs/Logging.md | 32 ++-- library/build.gradle.kts | 4 +- library/gradle.properties | 2 +- .../api/operation/model/QROperationParser .kt | 4 +- .../wultra/android/mtokensdk/common/Logger.kt | 142 ------------------ .../android/mtokensdk/inbox/InboxService.kt | 4 +- .../android/mtokensdk/log/WMTLogListener.kt | 35 +++++ .../wultra/android/mtokensdk/log/WMTLogger.kt | 95 ++++++++++++ .../mtokensdk/operation/OperationsService.kt | 17 +-- .../android/mtokensdk/operation/PACUtils.kt | 16 +- .../expiration/ExpirableOperation.kt | 4 +- .../expiration/OperationExpirationWatcher.kt | 22 +-- .../android/mtokensdk/push/PushService.kt | 7 +- 17 files changed, 195 insertions(+), 205 deletions(-) delete mode 100644 library/src/main/java/com/wultra/android/mtokensdk/common/Logger.kt create mode 100644 library/src/main/java/com/wultra/android/mtokensdk/log/WMTLogListener.kt create mode 100644 library/src/main/java/com/wultra/android/mtokensdk/log/WMTLogger.kt diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4f989e8..a8b0839 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,7 @@ on: jobs: build: name: Build - runs-on: macos-latest + runs-on: ubuntu-latest steps: - name: Checkout the repo uses: actions/checkout@v2 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3b8acd4..7f70ab8 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,7 +10,7 @@ on: jobs: ktlint: name: ktlint - runs-on: macos-latest + runs-on: ubuntu-latest steps: - name: Checkout the repo uses: actions/checkout@v2 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 43fe65d..7a8b20c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ on: jobs: tests: name: Tests - runs-on: macos-latest + runs-on: ubuntu-latest steps: - name: Checkout the repo uses: actions/checkout@v2 @@ -33,6 +33,11 @@ jobs: OP_URL: ${{ secrets.TESTS_OP_URL }} IN_URL: ${{ secrets.TESTS_IN_URL }} run: echo -e tests.sdk.cloudServerUrl="$CL_URL"\\ntests.sdk.cloudServerLogin="$CL_LGN"\\ntests.sdk.cloudServerPassword="$CL_PWD"\\ntests.sdk.cloudApplicationId="$CL_AID"\\ntests.sdk.enrollmentServerUrl="$ER_URL"\\ntests.sdk.operationsServerUrl="$OP_URL"\\ntests.sdk.inboxServerUrl="$IN_URL"\\ntests.sdk.sdkConfig="$SDK_CONFIG" > configs/integration-tests.properties + - name: Enable KVM + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm - name: Test the app (integration tests) uses: reactivecircus/android-emulator-runner@v2 with: diff --git a/docs/Changelog.md b/docs/Changelog.md index bb05f69..cd4d2cc 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -1,5 +1,10 @@ # Changelog +## 1.11.0 (May, 2024) + +- Changed name of the log class to the `WMTLogger` +- Added listener to the log class + ## 1.10.0 - Removed currentServerTime() method [(#139)](https://github.com/wultra/mtoken-sdk-android/pull/139) - Improved operations handling [(#138)](https://github.com/wultra/mtoken-sdk-android/pull/138) diff --git a/docs/Logging.md b/docs/Logging.md index 39d098b..ed37ab5 100644 --- a/docs/Logging.md +++ b/docs/Logging.md @@ -1,34 +1,30 @@ # Logging -For logging purposes, WMT uses the `Logger` class inside the `com.wultra.android.mtokensdk.common` package that prints to the console. +The library is intensively logging into the console via `WMTLogger`. - -Note that `Logger` is internally using `android.util.Log` class with verbosity ERROR, WARNING, and DEBUG and is subjected to its internal logic. + +`WMTLogger` calls internally the `android.util.Log` class. ### Verbosity Level You can limit the amount of logged information via the `verboseLevel` static property. -| Level | Description | -| --- | --- | -| `OFF` | Silences all messages. | -| `ERROR` | Only errors will be printed to the console. | +| Level | Description | +|-----------------------|-----------------------------------------------------| +| `OFF` | Silences all messages. | +| `ERROR` | Only errors will be printed to the console. | | `WARNING` _(default)_ | Errors and warnings will be printed to the console. | -| `DEBUG` | All messages will be printed to the console. | +| `DEBUG` | All messages will be printed to the console. | -Example configuration: - -```kotlin -import com.wultra.android.mtokensdk.common.Logger +### Networking Logs -Logger.verboseLevel = Logger.VerboseLevel.DEBUG -``` +Networking logs are managed by the [networking library and it's logger](https://github.com/wultra/networking-android) -### Networking Logs +### Log Listener -All requests and responses are logged in the `DEBUG` level. +The `WMTLogger` 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). - -In case you provided your own OkHttp instance, you need to set up your own logging for monitoring the traffic via the OkHttp interceptors. + +Log listener comes in handy when you want to log into a file or some online service. diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 43a1b45..9b1cd79 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -84,7 +84,7 @@ dependencies { // DO NOT UPGRADE ABOVE 3.12.X! Version 3.12 is the last version supporting TLS 1 and 1.1 // If upgraded, the app will crash on android 4.4 implementation("com.squareup.okhttp3:okhttp:3.12.13") - implementation("com.wultra.android.powerauth:powerauth-networking:1.3.0") + implementation("com.wultra.android.powerauth:powerauth-networking:1.4.0") // Dependencies compileOnly("com.wultra.android.powerauth:powerauth-sdk:1.8.0") @@ -96,7 +96,7 @@ dependencies { // Android tests androidTestImplementation("com.jakewharton.threetenabp:threetenabp:1.1.1") androidTestImplementation("com.wultra.android.powerauth:powerauth-sdk:1.8.0") - androidTestImplementation("com.wultra.android.powerauth:powerauth-networking:1.3.0") + androidTestImplementation("com.wultra.android.powerauth:powerauth-networking:1.4.0") androidTestImplementation("androidx.test:runner:1.5.2") androidTestImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test:core:1.5.0") diff --git a/library/gradle.properties b/library/gradle.properties index bf4854f..d66e5ce 100644 --- a/library/gradle.properties +++ b/library/gradle.properties @@ -14,6 +14,6 @@ # and limitations under the License. # -VERSION_NAME=1.8.3-SNAPSHOT +VERSION_NAME=1.11.0-SNAPSHOT GROUP_ID=com.wultra.android.mtokensdk ARTIFACT_ID=wultra-mtoken-sdk diff --git a/library/src/main/java/com/wultra/android/mtokensdk/api/operation/model/QROperationParser .kt b/library/src/main/java/com/wultra/android/mtokensdk/api/operation/model/QROperationParser .kt index 0849509..a79b5c1 100644 --- a/library/src/main/java/com/wultra/android/mtokensdk/api/operation/model/QROperationParser .kt +++ b/library/src/main/java/com/wultra/android/mtokensdk/api/operation/model/QROperationParser .kt @@ -18,7 +18,7 @@ package com.wultra.android.mtokensdk.api.operation.model import android.annotation.SuppressLint import android.util.Base64 -import com.wultra.android.mtokensdk.common.Logger +import com.wultra.android.mtokensdk.log.WMTLogger import java.math.BigDecimal import java.text.SimpleDateFormat @@ -96,7 +96,7 @@ class QROperationParser { return QROperation(operationId, title, message, formData, nonce, flags, totp, signedData, signature, isNewerFormat) } catch (e: IllegalArgumentException) { - Logger.e(e.message ?: "Payload is not a valid QR operation") + WMTLogger.e(e.message ?: "Payload is not a valid QR operation") throw e } } diff --git a/library/src/main/java/com/wultra/android/mtokensdk/common/Logger.kt b/library/src/main/java/com/wultra/android/mtokensdk/common/Logger.kt deleted file mode 100644 index be32c4f..0000000 --- a/library/src/main/java/com/wultra/android/mtokensdk/common/Logger.kt +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2022 Wultra s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions - * and limitations under the License. - */ - -package com.wultra.android.mtokensdk.common - -import android.util.Log -import okhttp3.Headers -import okhttp3.OkHttpClient -import okhttp3.Response -import okio.Buffer -import java.lang.StringBuilder - -/* ktlint-disable indent */ - -/** - * Logger provides simple logging facility. - * - * Logs are written with "WMT" tag to standard [android.util.Log] logger. - */ -class Logger { - - enum class VerboseLevel { - /** Silences all messages. */ - OFF, - /** Only errors will be printed into the log. */ - ERROR, - /** Errors and warnings will be printed into the log. */ - WARNING, - /** All messages will be printed into the log. */ - DEBUG - } - - companion object { - - /** Current verbose level. */ - @JvmStatic - var verboseLevel = VerboseLevel.WARNING - - private val tag = "WMT" - - internal fun d(message: String) { - if (verboseLevel.ordinal >= VerboseLevel.DEBUG.ordinal) { - Log.d(tag, message) - } - } - - internal fun d(fn: () -> String) { - if (verboseLevel.ordinal >= VerboseLevel.DEBUG.ordinal) { - Log.d(tag, fn()) - } - } - - internal fun w(message: String) { - if (verboseLevel.ordinal >= VerboseLevel.WARNING.ordinal) { - Log.w(tag, message) - } - } - - internal fun w(fn: () -> String) { - if (verboseLevel.ordinal >= VerboseLevel.WARNING.ordinal) { - Log.w(tag, fn()) - } - } - - internal fun e(message: String, t: Throwable? = null) { - if (verboseLevel.ordinal >= VerboseLevel.ERROR.ordinal) { - Log.e(tag, message, t) - } - } - - internal fun e(fn: () -> String) { - if (verboseLevel.ordinal >= VerboseLevel.ERROR.ordinal) { - Log.e(tag, fn()) - } - } - - internal fun configure(builder: OkHttpClient.Builder) { - builder.addInterceptor { chain -> - val request = chain.request() - d { - var body = "" - try { - val buffer = Buffer() - request.newBuilder().build().body()?.writeTo(buffer) - body = buffer.readUtf8() - } catch (e: Throwable) { - e("Failed to parse request body") - } - - "\n--- WMT REQUEST ---" + - "\n- URL: ${request.method()} - ${request.url()}" + - "\n- Headers: ${request.headers().forLog()}" + - "\n- Body: $body" - } - - val response: Response - - try { - response = chain.proceed(request) - } catch (e: Throwable) { - d { - "\n--- WMT REQUEST FAILED ---" + - "\n- URL: ${request.method()} - ${request.url()}" + - "\n- Error: $e" - } - throw e - } - - d { - "\n--- WMT RESPONSE ---" + - "\n- URL: ${response.request().method()} - ${response.request().url()}" + - "\n- Status code: ${response.code()}" + - "\n- Headers: ${response.headers().forLog()}" + - "\n- Body: ${response.peekBody(10_000).string()}" // allow max 10 KB of text - } - - response - } - } - } -} - -private fun Headers.forLog(): String { - val result = StringBuilder() - for (i in 0 until size()) { - result.append("\n - ").append(name(i)).append(": ").append(value(i)) - } - return result.toString() -} diff --git a/library/src/main/java/com/wultra/android/mtokensdk/inbox/InboxService.kt b/library/src/main/java/com/wultra/android/mtokensdk/inbox/InboxService.kt index 82b65d0..81eb77a 100644 --- a/library/src/main/java/com/wultra/android/mtokensdk/inbox/InboxService.kt +++ b/library/src/main/java/com/wultra/android/mtokensdk/inbox/InboxService.kt @@ -21,7 +21,6 @@ import com.wultra.android.mtokensdk.api.inbox.* import com.wultra.android.mtokensdk.api.inbox.model.GetList import com.wultra.android.mtokensdk.api.inbox.model.GetMessageDetail import com.wultra.android.mtokensdk.api.inbox.model.SetMessageRead -import com.wultra.android.mtokensdk.common.Logger import com.wultra.android.mtokensdk.operation.OperationsUtils import com.wultra.android.powerauth.networking.IApiCallResponseListener import com.wultra.android.powerauth.networking.OkHttpBuilderInterceptor @@ -41,8 +40,7 @@ fun PowerAuthSDK.createInboxService(appContext: Context, baseURL: String, okHttp fun PowerAuthSDK.createInboxService(appContext: Context, baseURL: String, strategy: SSLValidationStrategy, userAgent: UserAgent? = null): IInboxService { val builder = OkHttpClient.Builder() strategy.configure(builder) - Logger.configure(builder) - return createInboxService(appContext, baseURL, builder.build(), userAgent) + return InboxService(builder.build(), baseURL, this, appContext, null, userAgent) } class InboxService( diff --git a/library/src/main/java/com/wultra/android/mtokensdk/log/WMTLogListener.kt b/library/src/main/java/com/wultra/android/mtokensdk/log/WMTLogListener.kt new file mode 100644 index 0000000..e8f44ed --- /dev/null +++ b/library/src/main/java/com/wultra/android/mtokensdk/log/WMTLogListener.kt @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024, Wultra s.r.o. (www.wultra.com). + * + * All rights reserved. This source code can be used only for purposes specified + * by the given license contract signed by the rightful deputy of Wultra s.r.o. + * This source code can be used only by the owner of the license. + * + * Any disputes arising in respect of this agreement (license) shall be brought + * before the Municipal Court of Prague. + */ + +package com.wultra.android.mtokensdk.log + +/** Log listener receives logs from the library logger for further processing. */ +interface WMTLogListener { + /** + * If the listener should follow selected verbosity level. + * + * When set to true, then (for example) if [WMTLogger.VerboseLevel.ERROR] is selected as a [WMTLogger.verboseLevel], only [error] methods will be called. + * When set to false, all methods might be called no matter the selected [WMTLogger.verboseLevel]. + */ + val followVerboseLevel: Boolean + + /** Error log */ + fun error(message: String) + + /** Warning log */ + fun warning(message: String) + + /** Info log */ + fun info(message: String) + + /** Debug log */ + fun debug(message: String) +} diff --git a/library/src/main/java/com/wultra/android/mtokensdk/log/WMTLogger.kt b/library/src/main/java/com/wultra/android/mtokensdk/log/WMTLogger.kt new file mode 100644 index 0000000..aa6c239 --- /dev/null +++ b/library/src/main/java/com/wultra/android/mtokensdk/log/WMTLogger.kt @@ -0,0 +1,95 @@ +/* + * Copyright 2022 Wultra s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + */ + +package com.wultra.android.mtokensdk.log + +import android.util.Log + +/** + * Logger provides simple logging facility. + * + * Logs are written with "WMT" tag to standard [android.util.Log] logger. + * You can set [logListener] to start listening on the + */ +@Suppress("MemberVisibilityCanBePrivate") +class WMTLogger { + + /** Level of the log which should be effectively logged. */ + enum class VerboseLevel { + /** Silences all messages. */ + OFF, + /** Only errors will be printed into the log. */ + ERROR, + /** Errors and warnings will be printed into the log. */ + WARNING, + /** Info logs, errors and warnings will be printed into the log. */ + INFO, + /** All messages will be printed into the log. */ + DEBUG + } + + companion object { + + /** Current verbose level. */ + @JvmStatic var verboseLevel = VerboseLevel.WARNING + + /** Listener that can tap into the log stream and process it on it's own. */ + @JvmStatic var logListener: WMTLogListener? = null + + private val tag = "WMT" + + private fun log(valueFn: () -> String, allowedLevel: VerboseLevel, logFn: (String?, String) -> Unit, listenerFn: ((String) -> Unit)?) { + val shouldProcess = verboseLevel.ordinal >= allowedLevel.ordinal + val log = if (shouldProcess || logListener?.followVerboseLevel == false) valueFn() else return + if (shouldProcess) { + logFn(tag, log) + } + listenerFn?.invoke(log) + } + + internal fun d(message: String) { + d { message } + } + + internal fun d(fn: () -> String) { + log(fn, VerboseLevel.DEBUG, Log::d, logListener?.let { it::debug }) + } + + internal fun w(message: String) { + w { message } + } + + internal fun w(fn: () -> String) { + log(fn, VerboseLevel.WARNING, Log::w, logListener?.let { it::warning }) + } + + internal fun i(message: String) { + i { message } + } + + internal fun i(fn: () -> String) { + log(fn, VerboseLevel.INFO, Log::i, logListener?.let { it::info }) + } + + internal fun e(message: String) { + e { message } + } + + internal fun e(fn: () -> String) { + log(fn, VerboseLevel.ERROR, Log::e, logListener?.let { it::error }) + } + } +} diff --git a/library/src/main/java/com/wultra/android/mtokensdk/operation/OperationsService.kt b/library/src/main/java/com/wultra/android/mtokensdk/operation/OperationsService.kt index 9aa5623..91c18f8 100644 --- a/library/src/main/java/com/wultra/android/mtokensdk/operation/OperationsService.kt +++ b/library/src/main/java/com/wultra/android/mtokensdk/operation/OperationsService.kt @@ -21,7 +21,7 @@ import com.google.gson.GsonBuilder import com.wultra.android.mtokensdk.api.apiErrorForListener import com.wultra.android.mtokensdk.api.operation.* import com.wultra.android.mtokensdk.api.operation.model.* -import com.wultra.android.mtokensdk.common.Logger +import com.wultra.android.mtokensdk.log.WMTLogger import com.wultra.android.powerauth.networking.IApiCallResponseListener import com.wultra.android.powerauth.networking.OkHttpBuilderInterceptor import com.wultra.android.powerauth.networking.UserAgent @@ -64,11 +64,10 @@ fun PowerAuthSDK.createOperationsService(appContext: Context, baseURL: String, h * @param gsonBuilder Custom GSON builder for deserialization of request. If you want to provide or own * deserialization logic, we recommend adding to the instance obtained from the OperationsUtils.defaultGsonBuilder(). */ -fun PowerAuthSDK.createOperationsService(appContext: Context, baseURL: String, strategy: SSLValidationStrategy, userAgent: UserAgent? = null, gsonBuilder: GsonBuilder? = null): IOperationsService { +fun PowerAuthSDK.createOperationsService(appContext: Context, baseURL: String, strategy: SSLValidationStrategy = SSLValidationStrategy.default(), userAgent: UserAgent? = null, gsonBuilder: GsonBuilder? = null): IOperationsService { val builder = OkHttpClient.Builder() strategy.configure(builder) - Logger.configure(builder) - return createOperationsService(appContext, baseURL, builder.build(), userAgent, gsonBuilder) + return OperationsService(this, appContext, builder.build(), baseURL, null, userAgent, gsonBuilder) } private typealias GetOperationsCallback = (result: Result>) -> Unit @@ -179,7 +178,7 @@ class OperationsService: IOperationsService { } }) } else { - Logger.d("getOperation requested, but another request already running") + WMTLogger.w("getOperation requested, but another request already running") } } } @@ -302,7 +301,7 @@ class OperationsService: IOperationsService { @Synchronized override fun startPollingOperations(pollingInterval: Long, delayStart: Boolean) { if (timer != null) { - Logger.w("Polling already in progress") + WMTLogger.w("Polling already in progress") return } @@ -313,7 +312,7 @@ class OperationsService: IOperationsService { } val adjustedInterval = if (pollingInterval < minimumTimePollingInterval) { - Logger.w("Operations polling interval: $pollingInterval, must not be set below $minimumTimePollingInterval to prevent server overload.") + WMTLogger.w("Operations polling interval: $pollingInterval, must not be set below $minimumTimePollingInterval to prevent server overload.") minimumTimePollingInterval } else { pollingInterval @@ -330,13 +329,13 @@ class OperationsService: IOperationsService { adjustedInterval ) timer = t - Logger.d("Polling started with $pollingInterval milliseconds interval") + WMTLogger.i("Polling started with $pollingInterval milliseconds interval") } override fun stopPollingOperations() { timer?.cancel() timer = null - Logger.d("Operation polling stopped") + WMTLogger.i("Operation polling stopped") } } diff --git a/library/src/main/java/com/wultra/android/mtokensdk/operation/PACUtils.kt b/library/src/main/java/com/wultra/android/mtokensdk/operation/PACUtils.kt index 186a159..a0979c4 100644 --- a/library/src/main/java/com/wultra/android/mtokensdk/operation/PACUtils.kt +++ b/library/src/main/java/com/wultra/android/mtokensdk/operation/PACUtils.kt @@ -20,7 +20,7 @@ import android.net.Uri import android.util.Base64 import com.google.gson.Gson import com.google.gson.annotations.SerializedName -import com.wultra.android.mtokensdk.common.Logger +import com.wultra.android.mtokensdk.log.WMTLogger /** * Utility class used for handling Proximity Anti-fraud Checks @@ -48,7 +48,7 @@ class PACUtils { // Deeplink can have two query items with operationId & optional totp or single query item with JWT value uri.getQueryParameter("oid")?.let { operationId -> if (uri.query?.contains(operationId) == false) { - Logger.e("Operation could not be resolved - probably contains invalid characters - please, encode the URL first") + WMTLogger.e("Operation could not be resolved - probably contains invalid characters - please, encode the URL first") return null } val totp = uri.getQueryParameter("totp") ?: uri.getQueryParameter("potp") @@ -56,11 +56,11 @@ class PACUtils { } ?: uri.queryParameterNames.firstOrNull()?.let { return parseJWT(uri.getQueryParameter(it) ?: "") } ?: run { - Logger.e("Failed to parse deeplink. Valid keys not found in Uri: $uri") + WMTLogger.e("Failed to parse deeplink. Valid keys not found in Uri: $uri") return null } } catch (t: Throwable) { - Logger.e("Failed to parse deeplink - $t") + WMTLogger.e("Failed to parse deeplink - $t") return null } } @@ -88,16 +88,16 @@ class PACUtils { val json = String(dataPayload, Charsets.UTF_8) Gson().fromJson(json, PACData::class.java) } catch (e: Exception) { - Logger.e("Failed to decode QR JWT from: $code") - Logger.e("With error: ${e.message}") + WMTLogger.e("Failed to decode QR JWT from: $code") + WMTLogger.e("With error: ${e.message}") null } } else { - Logger.e("JWT Payload is empty, jwtParts contain: $jwtParts") + WMTLogger.e("JWT Payload is empty, jwtParts contain: $jwtParts") } } - Logger.e("Failed to decode QR JWT from: $jwtParts") + WMTLogger.e("Failed to decode QR JWT from: $jwtParts") return null } } diff --git a/library/src/main/java/com/wultra/android/mtokensdk/operation/expiration/ExpirableOperation.kt b/library/src/main/java/com/wultra/android/mtokensdk/operation/expiration/ExpirableOperation.kt index 08c668e..4e19451 100644 --- a/library/src/main/java/com/wultra/android/mtokensdk/operation/expiration/ExpirableOperation.kt +++ b/library/src/main/java/com/wultra/android/mtokensdk/operation/expiration/ExpirableOperation.kt @@ -17,7 +17,7 @@ package com.wultra.android.mtokensdk.operation.expiration import com.wultra.android.mtokensdk.api.operation.model.IOperation -import com.wultra.android.mtokensdk.common.Logger +import com.wultra.android.mtokensdk.log.WMTLogger import org.threeten.bp.ZonedDateTime /** @@ -37,7 +37,7 @@ interface ExpirableOperation { return if (this is IOperation && other is IOperation) { id == other.id && data == other.data && expires == other.expires } else { - Logger.w("ExpirableOperation: Fallbacked to comparing `WMTExpirableOperation`s by reference.") + WMTLogger.w("ExpirableOperation: Fallbacked to comparing `WMTExpirableOperation`s by reference.") this === other } } diff --git a/library/src/main/java/com/wultra/android/mtokensdk/operation/expiration/OperationExpirationWatcher.kt b/library/src/main/java/com/wultra/android/mtokensdk/operation/expiration/OperationExpirationWatcher.kt index e5105d2..3d3d196 100644 --- a/library/src/main/java/com/wultra/android/mtokensdk/operation/expiration/OperationExpirationWatcher.kt +++ b/library/src/main/java/com/wultra/android/mtokensdk/operation/expiration/OperationExpirationWatcher.kt @@ -21,7 +21,7 @@ package com.wultra.android.mtokensdk.operation.expiration import android.os.Handler import android.os.Looper import androidx.annotation.MainThread -import com.wultra.android.mtokensdk.common.Logger +import com.wultra.android.mtokensdk.log.WMTLogger import java.util.* import kotlin.math.max @@ -90,12 +90,12 @@ class OperationExpirationWatcher { // Operation can expire during the networking communication. Such operation // would be lost and never reported as expired. if (op.isExpired(currentDate)) { - Logger.w("OperationExpirationWatcher: You're adding an expired operation to watch.") + WMTLogger.w("OperationExpirationWatcher: You're adding an expired operation to watch.") } } if (operations.isEmpty()) { - Logger.w("OperationExpirationWatcher: Cannot watch empty array of operations") + WMTLogger.w("OperationExpirationWatcher: Cannot watch empty array of operations") return@synchronized operationsToWatch } @@ -103,16 +103,16 @@ class OperationExpirationWatcher { for (op in operations) { // filter already added operations if (operationsToWatch.any { it.equals(op) }) { - Logger.w("OperationExpirationWatcher: Operation cannot be watched - already there.") + WMTLogger.w("OperationExpirationWatcher: Operation cannot be watched - already there.") } else { opsToWatch.add(op) } } if (opsToWatch.isEmpty()) { - Logger.w("OperationExpirationWatcher: All operations are already watched") + WMTLogger.w("OperationExpirationWatcher: All operations are already watched") } else { - Logger.d("OperationExpirationWatcher: Adding ${opsToWatch.count()} operation to watch.") + WMTLogger.i("OperationExpirationWatcher: Adding ${opsToWatch.count()} operation to watch.") operationsToWatch.addAll(opsToWatch) prepareTimer() } @@ -156,10 +156,10 @@ class OperationExpirationWatcher { // when nil is provided, we consider it as "stop all" if (operations != null) { operationsToWatch.removeAll { current -> operations.any { toRemove -> toRemove.equals(current) } } - Logger.d("OperationExpirationWatcher: Stopped watching ${operations.count()} operations.") + WMTLogger.i("OperationExpirationWatcher: Stopped watching ${operations.count()} operations.") } else { operationsToWatch.clear() - Logger.d("OperationExpirationWatcher: Stopped watching all operations.") + WMTLogger.i("OperationExpirationWatcher: Stopped watching all operations.") } prepareTimer() } @@ -175,7 +175,7 @@ class OperationExpirationWatcher { timer = null if (operationsToWatch.isEmpty()) { - Logger.d("OperationExpirationWatcher: No operations to watch.") + WMTLogger.d("OperationExpirationWatcher: No operations to watch.") return } @@ -190,7 +190,7 @@ class OperationExpirationWatcher { // This leads to a minimal "expire report time" of 5 seconds. val interval = max(5, firstOp.expires.toEpochSecond() - currentDateProvider.getCurrentDate().toEpochSecond()) - Logger.d("OperationExpirationWatcher: Scheduling operation expire check in ${interval.toInt()} seconds.") + WMTLogger.d("OperationExpirationWatcher: Scheduling operation expire check in ${interval.toInt()} seconds.") val t = Timer("OperationsExpirationWatcherTimer", false) t.schedule( @@ -207,7 +207,7 @@ class OperationExpirationWatcher { operationsToWatch.removeAll { it.isExpired(currentDate) } prepareTimer() Handler(Looper.getMainLooper()).post { - Logger.d("OperationExpirationWatcher: Reporting ${expiredOps.count()} expired operations.") + WMTLogger.i("OperationExpirationWatcher: Reporting ${expiredOps.count()} expired operations.") listener?.operationsExpired(expiredOps) } } diff --git a/library/src/main/java/com/wultra/android/mtokensdk/push/PushService.kt b/library/src/main/java/com/wultra/android/mtokensdk/push/PushService.kt index e4fb711..3001c54 100644 --- a/library/src/main/java/com/wultra/android/mtokensdk/push/PushService.kt +++ b/library/src/main/java/com/wultra/android/mtokensdk/push/PushService.kt @@ -21,7 +21,7 @@ import com.wultra.android.mtokensdk.api.push.PushApi import com.wultra.android.mtokensdk.api.push.PushRegistrationRequest import com.wultra.android.mtokensdk.api.push.model.Platform import com.wultra.android.mtokensdk.api.push.model.PushRegistrationRequestObject -import com.wultra.android.mtokensdk.common.Logger +import com.wultra.android.mtokensdk.log.WMTLogger import com.wultra.android.powerauth.networking.IApiCallResponseListener import com.wultra.android.powerauth.networking.OkHttpBuilderInterceptor import com.wultra.android.powerauth.networking.UserAgent @@ -56,7 +56,6 @@ fun PowerAuthSDK.createPushService(appContext: Context, baseURL: String, okHttpC fun PowerAuthSDK.createPushService(appContext: Context, baseURL: String, strategy: SSLValidationStrategy, userAgent: UserAgent? = null): IPushService { val builder = OkHttpClient.Builder() strategy.configure(builder) - Logger.configure(builder) return createPushService(appContext, baseURL, builder.build(), userAgent) } @@ -85,7 +84,7 @@ class PushService(okHttpClient: OkHttpClient, baseURL: String, powerAuthSDK: Pow } override fun onFailure(error: ApiError) { - Logger.e("Failed to register fcm token for WMT push notifications.") + WMTLogger.e("Failed to register fcm token for WMT push notifications.") callback(Result.failure(ApiErrorException(error))) } } @@ -101,7 +100,7 @@ class PushService(okHttpClient: OkHttpClient, baseURL: String, powerAuthSDK: Pow } override fun onFailure(error: ApiError) { - Logger.e("Failed to register hms token for WMT push notifications.") + WMTLogger.e("Failed to register hms token for WMT push notifications.") callback(Result.failure(ApiErrorException(error))) } }