Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log improvements #54

Merged
merged 5 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,30 @@ The default value is always `en`. With other languages, we use values compliant

## Logging

For logging purposes `com.wultra.android.powerauth.networking.Logger` that prints to the console is used.
The library is intensively logging into the console via `WPNLogger`.

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

### Verbosity Level

You can limit the amount of logged information via `verboseLevel` property.

| Level | Description |
| --- | --- |
| `OFF` | Silences all messages. |
| `ERROR` | Only errors will be printed into the log. |
| Level | Description |
|-----------------------|---------------------------------------------------|
| `OFF` | Silences all messages. |
| `ERROR` | Only errors will be printed into the log. |
| `WARNING` _(default)_ | Errors and warnings will be printed into the log. |
| `DEBUG` | All messages will be printed into the log. |
| `DEBUG` | All messages will be printed into the log. |

### Log Listener

The `WPNLogger` 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 -->

<!-- begin remove -->
## Web Documentation
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.3.1-SNAPSHOT
VERSION_NAME=1.4.0-SNAPSHOT
GROUP_ID=com.wultra.android.powerauth
ARTIFACT_ID=powerauth-networking
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.wultra.android.powerauth.networking.data.StatusResponse
import com.wultra.android.powerauth.networking.error.ApiError
import com.wultra.android.powerauth.networking.error.ApiHttpException
import com.wultra.android.powerauth.networking.error.ErrorResponse
import com.wultra.android.powerauth.networking.log.WPNLogger
import com.wultra.android.powerauth.networking.processing.GsonRequestBodyBytes
import com.wultra.android.powerauth.networking.processing.GsonResponseBodyConverter
import com.wultra.android.powerauth.networking.tokens.IPowerAuthTokenListener
Expand Down Expand Up @@ -68,7 +69,7 @@ interface IApiCallResponseListener<T> {
*/
abstract class Api(
@PublishedApi internal val baseUrl: String,
@PublishedApi internal val okHttpClient: OkHttpClient,
okHttpClient: OkHttpClient,
@PublishedApi internal val powerAuthSDK: PowerAuthSDK,
@PublishedApi internal val gsonBuilder: GsonBuilder,
@PublishedApi internal val appContext: Context,
Expand All @@ -80,8 +81,16 @@ abstract class Api(
*/
var acceptLanguage = "en"

@PublishedApi internal val okHttpClient: OkHttpClient

@PublishedApi internal val tokenProvider: IPowerAuthTokenProvider = tokenProvider ?: TokenManager(appContext, powerAuthSDK.tokenStore)

init {
val builder = okHttpClient.newBuilder()
WPNLogger.configure(builder)
this.okHttpClient = builder.build()
}

// PUBLIC API

inline fun <reified TRequestData: BaseRequest, reified TResponseData: StatusResponse> post(
Expand Down Expand Up @@ -182,12 +191,14 @@ abstract class Api(
if (ts.isTimeSynchronized) {
completion(Result.success(Unit))
} else {
WPNLogger.i("Time is not synchronized, requesting synchronization first.")
ts.synchronizeTime(object: ITimeSynchronizationListener {
override fun onTimeSynchronizationSucceeded() {
completion(Result.success(Unit))
}

override fun onTimeSynchronizationFailed(t: Throwable) {
WPNLogger.e("Time failed to synchronize, stopping whole request: $t")
completion(Result.failure(t))
}
})
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.wultra.android.powerauth.networking.log

/** Log listener receives logs from the library logger for further processing. */
interface WPNLogListener {
/**
* If the listener should follow selected verbosity level.
*
* When set to true, then (for example) if [WPNLogger.VerboseLevel.ERROR] is selected as a [WPNLogger.verboseLevel], only [error] methods will be called.
* When set to false, all methods might be called no matter the selected [WPNLogger.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