Skip to content

Commit

Permalink
Log improvements (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
kober32 authored May 17, 2024
1 parent 8ace09b commit 3cc9a20
Show file tree
Hide file tree
Showing 17 changed files with 195 additions and 205 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
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.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)
Expand Down
32 changes: 14 additions & 18 deletions docs/Logging.md
Original file line number Diff line number Diff line change
@@ -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`.

<!-- begin box warning -->
Note that `Logger` is internally using `android.util.Log` class with verbosity ERROR, WARNING, and DEBUG and is subjected to its internal logic.
<!-- begin box info -->
`WMTLogger` calls internally the `android.util.Log` class.
<!-- end -->

### 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).

<!-- begin box warning -->
In case you provided your own OkHttp instance, you need to set up your own logging for monitoring the traffic via the OkHttp interceptors.
<!-- begin box info -->
Log listener comes in handy when you want to log into a file or some online service.
<!-- end -->
4 changes: 2 additions & 2 deletions library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
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.8.3-SNAPSHOT
VERSION_NAME=1.11.0-SNAPSHOT
GROUP_ID=com.wultra.android.mtokensdk
ARTIFACT_ID=wultra-mtoken-sdk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
}
Expand Down
142 changes: 0 additions & 142 deletions library/src/main/java/com/wultra/android/mtokensdk/common/Logger.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
Loading

0 comments on commit 3cc9a20

Please sign in to comment.