From d706d77da3228e16dd1626e051bd825e2e8bc782 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 17 Oct 2023 15:12:05 +0200 Subject: [PATCH] feat: add logger with userId and clientId (#2139) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add logger with userId and clientId (#2100) * feat: add logger with userid and clientid * update lib version * added some documentation to the KaliumLogger tags * moved creating string tag to Tag sealed class * fix detekt * fix tests * trigger build * fixes after cherry pick * fix detekt * revert wrong change after automatic cherry-pick --------- Co-authored-by: Michał Saleniuk <30429749+saleniuk@users.noreply.github.com> Co-authored-by: Michał Saleniuk --- .../com/wire/kalium/cli/CLIApplication.kt | 12 +- .../kalium/cryptography/CryptographyLogger.kt | 12 +- gradle/libs.versions.toml | 2 +- .../com/wire/kalium/logger/KaliumLogger.kt | 208 ++++++++++++------ .../com/wire/kalium/logic/CoreLogger.kt | 33 +-- .../kalium/logic/feature/UserSessionScope.kt | 13 +- .../wire/kalium/monkeys/MonkeyApplication.kt | 7 +- .../com/wire/kalium/monkeys/MonkeyLogger.kt | 14 +- .../wire/kalium/network/NetworkUtilLogger.kt | 13 +- .../wire/kalium/network/KaliumHttpLogger.kt | 4 +- .../kalium/network/KaliumKtorCustomLogging.kt | 11 +- .../com/wire/kalium/network/NetworkClient.kt | 14 +- .../com/wire/kalium/network/NetworkLogger.kt | 14 +- .../AuthenticatedNetworkContainerV0.kt | 11 +- .../AuthenticatedNetworkContainerV2.kt | 15 +- .../AuthenticatedNetworkContainerV3.kt | 12 +- .../AuthenticatedNetworkContainerV4.kt | 12 +- .../AuthenticatedNetworkContainerV5.kt | 12 +- .../AuthenticatedNetworkContainer.kt | 32 ++- .../kotlin/com/wire/kalium/api/ApiTest.kt | 13 +- .../kalium/api/common/SessionManagerTest.kt | 3 +- .../kalium/persistence/PersistenceLogger.kt | 12 +- 22 files changed, 292 insertions(+), 187 deletions(-) diff --git a/cli/src/commonMain/kotlin/com/wire/kalium/cli/CLIApplication.kt b/cli/src/commonMain/kotlin/com/wire/kalium/cli/CLIApplication.kt index a187a7c39cd..0086ee3a416 100644 --- a/cli/src/commonMain/kotlin/com/wire/kalium/cli/CLIApplication.kt +++ b/cli/src/commonMain/kotlin/com/wire/kalium/cli/CLIApplication.kt @@ -26,6 +26,7 @@ import com.github.ajalt.clikt.parameters.options.flag import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.types.enum import com.wire.kalium.logger.KaliumLogLevel +import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.logic.CoreLogger import com.wire.kalium.logic.CoreLogic import com.wire.kalium.logic.featureFlags.KaliumConfigs @@ -63,11 +64,12 @@ class CLIApplication : CliktCommand(allowMultipleSubcommands = true) { ) } - if (logOutputFile != null) { - CoreLogger.setLoggingLevel(logLevel, fileLogger) - } else { - CoreLogger.setLoggingLevel(logLevel) - } + CoreLogger.init( + KaliumLogger.Config( + logLevel, + if (logOutputFile != null) listOf(fileLogger) else emptyList(), + ) + ) currentContext.findObject()?.updateApiVersionsScheduler?.scheduleImmediateApiVersionUpdate() Unit diff --git a/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/CryptographyLogger.kt b/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/CryptographyLogger.kt index 91c04ae3624..ce2a728a1e2 100644 --- a/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/CryptographyLogger.kt +++ b/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/CryptographyLogger.kt @@ -18,20 +18,12 @@ package com.wire.kalium.cryptography -import co.touchlab.kermit.LogWriter -import com.wire.kalium.logger.KaliumLogLevel import com.wire.kalium.logger.KaliumLogger internal var kaliumLogger = KaliumLogger.disabled() object CryptographyLogger { - fun setLoggingLevel(level: KaliumLogLevel, vararg logWriters: LogWriter = arrayOf()) { - kaliumLogger = KaliumLogger( - config = KaliumLogger.Config( - severity = level, - tag = "Crypto" - ), - logWriters = logWriters - ) + fun init(config: KaliumLogger.Config) { + kaliumLogger = KaliumLogger(config = config, tag = "Crypto") } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 355b2291050..ebaa9590510 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -40,7 +40,7 @@ core-crypto = "1.0.0-rc.12" core-crypto-multiplatform = "0.6.0-rc.3-multiplatform-pre1" completeKotlin = "1.1.0" desugar-jdk = "2.0.3" -kermit = "1.2.2" +kermit = "2.0.1" detekt = "1.19.0" agp = "8.1.1" dokka = "1.8.20" diff --git a/logger/src/commonMain/kotlin/com/wire/kalium/logger/KaliumLogger.kt b/logger/src/commonMain/kotlin/com/wire/kalium/logger/KaliumLogger.kt index 22dd6697972..047ffba535a 100644 --- a/logger/src/commonMain/kotlin/com/wire/kalium/logger/KaliumLogger.kt +++ b/logger/src/commonMain/kotlin/com/wire/kalium/logger/KaliumLogger.kt @@ -19,8 +19,9 @@ package com.wire.kalium.logger import co.touchlab.kermit.LogWriter +import co.touchlab.kermit.LoggerConfig +import co.touchlab.kermit.MutableLoggerConfig import co.touchlab.kermit.Severity -import co.touchlab.kermit.StaticConfig import co.touchlab.kermit.platformLogWriter import co.touchlab.kermit.Logger as KermitLogger @@ -61,96 +62,179 @@ enum class KaliumLogLevel { DISABLED } +fun KaliumLogLevel.toMinSeverity(): Severity = when (this) { + KaliumLogLevel.VERBOSE -> Severity.Verbose + KaliumLogLevel.DEBUG -> Severity.Debug + KaliumLogLevel.INFO -> Severity.Info + KaliumLogLevel.WARN -> Severity.Warn + KaliumLogLevel.ERROR -> Severity.Error + KaliumLogLevel.DISABLED -> Severity.Assert +} + +fun Severity.toKaliumLogLevel(): KaliumLogLevel = when (this) { + Severity.Verbose -> KaliumLogLevel.VERBOSE + Severity.Debug -> KaliumLogLevel.DEBUG + Severity.Info -> KaliumLogLevel.INFO + Severity.Warn -> KaliumLogLevel.WARN + Severity.Error -> KaliumLogLevel.ERROR + Severity.Assert -> KaliumLogLevel.DISABLED +} + /** - * the logWriter is to create a custom writer other than the existing log writers from kermit to intercept the logs - * in the android case we use it to write the logs on file - * + * Custom logger writer which uses multiplatform [KermitLogger] underneath to allow to customize log message or tag. + * @param config the [Config] object which contains the configuration of the logger + * @param tag the [Tag] object which identifies the source of the log message. Can combine multiple data and turns it + * into structured String used by the [KermitLogger] so that it can be parsed back again to the [Tag] object. + * To know more how it behaves and what are the possibilities, take a look at the [Tag] sealed class and its subtypes. */ -class KaliumLogger(private val config: Config, vararg logWriters: LogWriter = arrayOf()) { +class KaliumLogger( + private val config: Config = Config.DEFAULT, + private val tag: Tag = Tag.Text("KaliumLogger") +) { - private var kermitLogger: KermitLogger + constructor( + config: Config = Config.DEFAULT, + tag: String = "KaliumLogger" + ) : this(config, Tag.Text(tag)) + private val kermitLogger: KermitLogger = KermitLogger( + config = config.kermitConfig() + ) - init { - kermitLogger = if (logWriters.isEmpty()) { - KermitLogger( - config = StaticConfig( - minSeverity = config.severityLevel, listOf(platformLogWriter()) - ), - tag = config.tag - ) - } else { - KermitLogger( - config = StaticConfig( - minSeverity = config.severityLevel, logWriters.asList() - ), - tag = config.tag - ) - } - } + private fun tag(): String = tag.tagString() - val severity = config.severity + fun logLevel(): KaliumLogLevel = config.logLevel() + /** + * Creates a new logger with custom tag that replaces the old tag and allows to specify which specific app flow, + * one of [ApplicationFlow], the logs sent by this logger relate to. + * When the logger already contains [Tag.UserClientText] type of logs, then user-related tag data will still be included, + * and this featureId tag part will be added as a prefix, to keep the standard pattern of the tag: "tag[userId|clientId]". + * In this case it will become "featureId:featureName[userId|clientId]". + * When current type of tag is [Tag.Text], then it will just replace it with the new one: "featureId:featureName". + */ @Suppress("unused") - fun withFeatureId(featureId: ApplicationFlow): KaliumLogger { - val currentLogger = this - currentLogger.kermitLogger = kermitLogger.withTag("featureId:${featureId.name.lowercase()}") - return currentLogger - } + fun withFeatureId(featureId: ApplicationFlow): KaliumLogger = KaliumLogger( + config = config, + tag = "featureId:${featureId.name.lowercase()}".let { + when (tag) { + is Tag.Text -> Tag.Text(it) + is Tag.UserClientText -> Tag.UserClientText(it, tag.data) + } + } + ) + + /** + * Creates a new logger with custom tag that replaces the old tag and allows to add user-related data to the tag. + * When the logger already contains [Tag.UserClientText] type of tag, then user-related tag data part will be replaced, + * and if it contained already some text tag prefix part, then the same prefix will be also included in the new one, + * to keep the standard pattern of the tag: "tag[userId|clientId]". + */ + @Suppress("unused") + fun withUserDeviceData(data: () -> UserClientData): KaliumLogger = KaliumLogger( + config = config, + tag = when (tag) { + is Tag.Text -> Tag.UserClientText(tag.text, data) + is Tag.UserClientText -> Tag.UserClientText(tag.prefix, data) + } + ) @Suppress("unused") - fun v(message: String, throwable: Throwable? = null) = - throwable?.let { - kermitLogger.v(message, throwable) - } ?: kermitLogger.v(message) + fun v(message: String, throwable: Throwable? = null, tag: String = this.tag()) = + kermitLogger.v(message, throwable, tag) @Suppress("unused") - fun d(message: String, throwable: Throwable? = null) = - throwable?.let { - kermitLogger.d(message, throwable) - } ?: kermitLogger.d(message) + fun d(message: String, throwable: Throwable? = null, tag: String = this.tag()) = + kermitLogger.d(message, throwable, tag) @Suppress("unused") - fun i(message: String, throwable: Throwable? = null) = - throwable?.let { - kermitLogger.i(message, throwable) - } ?: kermitLogger.i(message) + fun i(message: String, throwable: Throwable? = null, tag: String = this.tag()) = + kermitLogger.i(message, throwable, tag) @Suppress("unused") - fun w(message: String, throwable: Throwable? = null) = - throwable?.let { - kermitLogger.w(message, throwable) - } ?: kermitLogger.w(message) + fun w(message: String, throwable: Throwable? = null, tag: String = this.tag()) = + kermitLogger.w(message, throwable, tag) @Suppress("unused") - fun e(message: String, throwable: Throwable? = null) = - throwable?.let { - kermitLogger.e(message, throwable) - } ?: kermitLogger.e(message) + fun e(message: String, throwable: Throwable? = null, tag: String = this.tag()) = + kermitLogger.e(message, throwable, tag) class Config( - val severity: KaliumLogLevel, - val tag: String + val initialLevel: KaliumLogLevel, + val initialLogWriterList: List = listOf(platformLogWriter()) ) { - val severityLevel: Severity = when (severity) { - KaliumLogLevel.VERBOSE -> Severity.Verbose - KaliumLogLevel.DEBUG -> Severity.Debug - KaliumLogLevel.INFO -> Severity.Info - KaliumLogLevel.WARN -> Severity.Warn - KaliumLogLevel.ERROR -> Severity.Error - KaliumLogLevel.DISABLED -> Severity.Assert + private val mutableKermitConfig = object : MutableLoggerConfig { + override var logWriterList: List = initialLogWriterList + override var minSeverity: Severity = initialLevel.toMinSeverity() + } + + fun logLevel(): KaliumLogLevel = mutableKermitConfig.minSeverity.toKaliumLogLevel() + + fun kermitConfig(): LoggerConfig = mutableKermitConfig + + @Suppress("unused") + fun setLogLevel(level: KaliumLogLevel) { + mutableKermitConfig.minSeverity = level.toMinSeverity() + } + + @Suppress("unused") + fun setLogWriterList(logWriterList: List) { + mutableKermitConfig.logWriterList = logWriterList } companion object { - val DISABLED = Config( - severity = KaliumLogLevel.DISABLED, - tag = "KaliumLogger" + val DEFAULT = disabled() + fun disabled(): Config = Config( + initialLevel = KaliumLogLevel.DISABLED, + initialLogWriterList = listOf(platformLogWriter()), ) } } + /** + * Defined types of tags that can be provided to the [KaliumLogger] as a String text. + */ + sealed class Tag { + abstract fun tagString(): String + + /** + * Simple String text tag. + */ + data class Text(val text: String) : Tag() { + override fun tagString(): String = text + } + + /** + * User-related data tag. Contains String text prefix and [UserClientData] (userId and clientId). + * It will be added to the tag in the standard pattern: "tag[userId|clientId]", + * so it can be combined with a [Tag.Text] type by adding the tag text as a prefix in this one. + */ + data class UserClientText(val prefix: String, val data: () -> UserClientData) : Tag() { + override fun tagString(): String = data().let { "$prefix[${it.userId}|${it.clientId}]" } + } + } + + data class UserClientData(val userId: String, val clientId: String) { + + companion object { + private val regex = Regex("^.*\\[.+\\|.+\\]\$") + + /** + * Parses the user-related data from the String tag in the standard pattern: "tag[userId|clientId]". + * Returns null if the tag doesn't match the pattern, which means it does not contain user-related data. + */ + @Suppress("unused") + fun getFromTag(tag: String): UserClientData? = + if (tag.matches(regex)) { + tag.substringAfterLast("[").substringBefore("]").split("|") + .let { data -> UserClientData(data[0], data[1]) } + } else null + } + } + companion object { fun disabled(): KaliumLogger = KaliumLogger( - config = Config.DISABLED + config = Config.disabled(), + tag = "KaliumLogger" ) enum class ApplicationFlow { diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreLogger.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreLogger.kt index a4e0b1081d1..259de8370f6 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreLogger.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreLogger.kt @@ -18,7 +18,6 @@ package com.wire.kalium.logic -import co.touchlab.kermit.LogWriter import com.wire.kalium.cryptography.CryptographyLogger import com.wire.kalium.logger.KaliumLogLevel import com.wire.kalium.logger.KaliumLogger @@ -26,30 +25,22 @@ import com.wire.kalium.network.NetworkLogger import com.wire.kalium.network.NetworkUtilLogger import com.wire.kalium.persistence.PersistenceLogger +private var kaliumLoggerConfig = KaliumLogger.Config.disabled() internal var kaliumLogger = KaliumLogger.disabled() internal var callingLogger = KaliumLogger.disabled() object CoreLogger { - fun setLoggingLevel(level: KaliumLogLevel, vararg logWriters: LogWriter = arrayOf()) { - kaliumLogger = KaliumLogger( - config = KaliumLogger.Config( - severity = level, - tag = "CoreLogic" - ), - logWriters = logWriters - ) - callingLogger = KaliumLogger( - config = KaliumLogger.Config( - severity = level, - tag = "Calling" - ), - logWriters = logWriters - ) - - NetworkLogger.setLoggingLevel(level = level, logWriters = logWriters) - NetworkUtilLogger.setLoggingLevel(level = level, logWriters = logWriters) - CryptographyLogger.setLoggingLevel(level = level, logWriters = logWriters) - PersistenceLogger.setLoggingLevel(level = level, logWriters = logWriters) + fun init(config: KaliumLogger.Config) { + kaliumLoggerConfig = config + kaliumLogger = KaliumLogger(config = kaliumLoggerConfig, tag = "CoreLogic") + callingLogger = KaliumLogger(config = kaliumLoggerConfig, tag = "Calling") + NetworkLogger.init(config = config) + NetworkUtilLogger.init(config = config) + CryptographyLogger.init(config = config) + PersistenceLogger.init(config = config) + } + fun setLoggingLevel(level: KaliumLogLevel) { + kaliumLoggerConfig.setLogLevel(level) } } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt index 71b37ce9660..e63bb2fd2f1 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt @@ -18,6 +18,8 @@ package com.wire.kalium.logic.feature +import com.wire.kalium.logger.KaliumLogger +import com.wire.kalium.logger.obfuscateId import com.wire.kalium.logic.CoreFailure import com.wire.kalium.logic.GlobalKaliumScope import com.wire.kalium.logic.cache.MLSSelfConversationIdProvider @@ -286,6 +288,7 @@ import com.wire.kalium.logic.functional.Either import com.wire.kalium.logic.functional.isRight import com.wire.kalium.logic.functional.map import com.wire.kalium.logic.functional.onSuccess +import com.wire.kalium.logic.kaliumLogger import com.wire.kalium.logic.network.ApiMigrationManager import com.wire.kalium.logic.network.ApiMigrationV3 import com.wire.kalium.logic.network.SessionManagerImpl @@ -384,6 +387,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.cancel import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.launch import okio.Path.Companion.toPath import kotlin.coroutines.CoroutineContext @@ -422,6 +426,12 @@ class UserSessionScope internal constructor( } } + private val clientIdStateFlow = MutableStateFlow(null) + + private val userScopedLogger: KaliumLogger = kaliumLogger.withUserDeviceData { + KaliumLogger.UserClientData(userId.toLogString(), clientIdStateFlow.value?.value?.obfuscateId() ?: "") + } + private val cachedClientIdClearer: CachedClientIdClearer = object : CachedClientIdClearer { override fun invoke() { _clientId = null @@ -486,7 +496,8 @@ class UserSessionScope internal constructor( UserIdDTO(userId.value, userId.domain), userAgent, certificatePinning = kaliumConfigs.certPinningConfig, - mockEngine = kaliumConfigs.kaliumMockEngine?.mockEngine + mockEngine = kaliumConfigs.kaliumMockEngine?.mockEngine, + kaliumLogger = userScopedLogger ) private val featureSupport: FeatureSupport = FeatureSupportImpl( kaliumConfigs, diff --git a/monkeys/src/main/kotlin/com/wire/kalium/monkeys/MonkeyApplication.kt b/monkeys/src/main/kotlin/com/wire/kalium/monkeys/MonkeyApplication.kt index 56a4e802869..63790cc2a4e 100644 --- a/monkeys/src/main/kotlin/com/wire/kalium/monkeys/MonkeyApplication.kt +++ b/monkeys/src/main/kotlin/com/wire/kalium/monkeys/MonkeyApplication.kt @@ -27,6 +27,7 @@ import com.github.ajalt.clikt.parameters.options.default import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.types.enum import com.wire.kalium.logger.KaliumLogLevel +import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.logic.CoreLogger import com.wire.kalium.monkeys.importer.TestData import com.wire.kalium.monkeys.importer.TestDataImporter @@ -59,9 +60,11 @@ class MonkeyApplication : CliktCommand(allowMultipleSubcommands = true) { } if (logOutputFile != null) { - CoreLogger.setLoggingLevel(logLevel, fileLogger) + CoreLogger.init(KaliumLogger.Config(logLevel, listOf(fileLogger))) + MonkeyLogger.init(KaliumLogger.Config(logLevel, listOf(fileLogger))) } else { - CoreLogger.setLoggingLevel(logLevel) + CoreLogger.init(KaliumLogger.Config(logLevel, emptyList())) + MonkeyLogger.init(KaliumLogger.Config(logLevel, emptyList())) } MonkeyLogger.setLoggingLevel(logLevel, monkeyFileLogger) logger.i("Initializing Metrics Endpoint") diff --git a/monkeys/src/main/kotlin/com/wire/kalium/monkeys/MonkeyLogger.kt b/monkeys/src/main/kotlin/com/wire/kalium/monkeys/MonkeyLogger.kt index 0a9c0eedd54..4e96255b007 100644 --- a/monkeys/src/main/kotlin/com/wire/kalium/monkeys/MonkeyLogger.kt +++ b/monkeys/src/main/kotlin/com/wire/kalium/monkeys/MonkeyLogger.kt @@ -17,20 +17,14 @@ */ package com.wire.kalium.monkeys -import co.touchlab.kermit.LogWriter -import com.wire.kalium.logger.KaliumLogLevel import com.wire.kalium.logger.KaliumLogger +private var loggerConfig = KaliumLogger.Config.disabled() internal var logger = KaliumLogger.disabled() object MonkeyLogger { - fun setLoggingLevel(level: KaliumLogLevel, vararg logWriters: LogWriter = arrayOf()) { - logger = KaliumLogger( - config = KaliumLogger.Config( - severity = level, - tag = "InfiniteMonkeys" - ), - logWriters = logWriters - ) + fun init(config: KaliumLogger.Config) { + loggerConfig = config + logger = KaliumLogger(config = loggerConfig, tag = "InfiniteMonkeys") } } diff --git a/network-util/src/commonMain/kotlin/com/wire/kalium/network/NetworkUtilLogger.kt b/network-util/src/commonMain/kotlin/com/wire/kalium/network/NetworkUtilLogger.kt index 120ae5f77ed..88e6fe38f1f 100644 --- a/network-util/src/commonMain/kotlin/com/wire/kalium/network/NetworkUtilLogger.kt +++ b/network-util/src/commonMain/kotlin/com/wire/kalium/network/NetworkUtilLogger.kt @@ -18,22 +18,15 @@ package com.wire.kalium.network -import co.touchlab.kermit.LogWriter import com.wire.kalium.logger.KaliumLogLevel import com.wire.kalium.logger.KaliumLogger internal var kaliumUtilLogger = KaliumLogger.disabled() object NetworkUtilLogger { - fun setLoggingLevel(level: KaliumLogLevel, vararg logWriters: LogWriter = arrayOf()) { - kaliumUtilLogger = KaliumLogger( - config = KaliumLogger.Config( - severity = level, - tag = "Network" - ), - logWriters = logWriters - ) + fun init(config: KaliumLogger.Config) { + kaliumUtilLogger = KaliumLogger(config = config, tag = "NetworkUtil") } - val isRequestLoggingEnabled: Boolean get() = kaliumUtilLogger.severity in setOf(KaliumLogLevel.VERBOSE, KaliumLogLevel.DEBUG) + val isRequestLoggingEnabled: Boolean get() = kaliumUtilLogger.logLevel() in setOf(KaliumLogLevel.VERBOSE, KaliumLogLevel.DEBUG) } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/KaliumHttpLogger.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/KaliumHttpLogger.kt index 4df380a0723..ead54252014 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/KaliumHttpLogger.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/KaliumHttpLogger.kt @@ -19,6 +19,7 @@ package com.wire.kalium.network import com.wire.kalium.logger.KaliumLogLevel +import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.utils.obfuscatePath import com.wire.kalium.network.utils.obfuscatedJsonMessage import com.wire.kalium.util.serialization.toJsonElement @@ -40,7 +41,8 @@ import kotlinx.coroutines.Job internal class KaliumHttpLogger( private val level: LogLevel, - private val logger: Logger + private val logger: Logger, + private val kaliumLogger: KaliumLogger, ) { private val requestLog = mutableMapOf() private val responseLog = mutableMapOf() diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/KaliumKtorCustomLogging.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/KaliumKtorCustomLogging.kt index 7f3ef2bf009..119a2772c90 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/KaliumKtorCustomLogging.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/KaliumKtorCustomLogging.kt @@ -18,6 +18,7 @@ package com.wire.kalium.network +import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.utils.obfuscatePath import io.ktor.client.HttpClient import io.ktor.client.HttpClientConfig @@ -50,6 +51,7 @@ private val DisableLogging = AttributeKey("DisableLogging") @Suppress("TooGenericExceptionCaught", "EmptyFinallyBlock") public class KaliumKtorCustomLogging private constructor( public val logger: Logger, + public val kaliumLogger: KaliumLogger, public var level: LogLevel, public var filters: List<(HttpRequestBuilder) -> Boolean> = emptyList() ) { @@ -79,6 +81,11 @@ public class KaliumKtorCustomLogging private constructor( */ public var level: LogLevel = LogLevel.HEADERS + /** + * [KaliumLogger] instance to use + */ + var kaliumLogger: KaliumLogger = com.wire.kalium.network.kaliumLogger + /** * Log messages for calls matching a [predicate] */ @@ -164,7 +171,7 @@ public class KaliumKtorCustomLogging private constructor( } private fun logRequest(request: HttpRequestBuilder): OutgoingContent? { - val logger = KaliumHttpLogger(level, logger) + val logger = KaliumHttpLogger(level, logger, kaliumLogger) request.attributes.put(KaliumHttpCustomLogger, logger) logger.logRequest(request) @@ -179,7 +186,7 @@ public class KaliumKtorCustomLogging private constructor( override fun prepare(block: Config.() -> Unit): KaliumKtorCustomLogging { val config = Config().apply(block) - return KaliumKtorCustomLogging(config.logger, config.level, config.filters) + return KaliumKtorCustomLogging(config.logger, config.kaliumLogger, config.level, config.filters) } override fun install(plugin: KaliumKtorCustomLogging, scope: HttpClient) { diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/NetworkClient.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/NetworkClient.kt index 0dfbbcf2b1a..dfed74f4ba4 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/NetworkClient.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/NetworkClient.kt @@ -18,6 +18,7 @@ package com.wire.kalium.network +import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.networkContainer.KaliumUserAgentProvider import com.wire.kalium.network.serialization.mls import com.wire.kalium.network.serialization.xprotobuf @@ -50,11 +51,13 @@ internal class AuthenticatedNetworkClient( engine: HttpClientEngine, serverConfigDTO: ServerConfigDTO, bearerAuthProvider: BearerAuthProvider, + kaliumLogger: KaliumLogger, installCompression: Boolean = true ) { val httpClient: HttpClient = provideBaseHttpClient( networkStateObserver, engine, + kaliumLogger, installCompression ) { installWireDefaultRequest(serverConfigDTO) @@ -76,7 +79,7 @@ internal class UnauthenticatedNetworkClient( engine: HttpClientEngine, backendLinks: ServerConfigDTO ) { - val httpClient: HttpClient = provideBaseHttpClient(networkStateObserver, engine) { + val httpClient: HttpClient = provideBaseHttpClient(networkStateObserver, engine, kaliumLogger) { installWireDefaultRequest(backendLinks) } } @@ -91,7 +94,7 @@ internal class UnboundNetworkClient( networkStateObserver: NetworkStateObserver, engine: HttpClientEngine ) { - val httpClient: HttpClient = provideBaseHttpClient(networkStateObserver, engine) + val httpClient: HttpClient = provideBaseHttpClient(networkStateObserver, engine, kaliumLogger) } /** @@ -104,6 +107,7 @@ internal class AuthenticatedWebSocketClient( private val engine: HttpClientEngine, private val bearerAuthProvider: BearerAuthProvider, private val serverConfigDTO: ServerConfigDTO, + private val kaliumLogger: KaliumLogger, ) { /** * Creates a disposable [HttpClient] for a single use. @@ -112,7 +116,7 @@ internal class AuthenticatedWebSocketClient( * as the old one can be dead. */ fun createDisposableHttpClient(): HttpClient = - provideBaseHttpClient(networkStateObserver, engine) { + provideBaseHttpClient(networkStateObserver, engine, kaliumLogger) { installWireDefaultRequest(serverConfigDTO) installAuth(bearerAuthProvider) install(ContentNegotiation) { @@ -130,6 +134,7 @@ internal class AuthenticatedWebSocketClient( internal fun provideBaseHttpClient( networkStateObserver: NetworkStateObserver, engine: HttpClientEngine, + kaliumLogger: KaliumLogger, installCompression: Boolean = true, config: HttpClientConfig<*>.() -> Unit = {} ) = HttpClient(engine) { @@ -139,7 +144,8 @@ internal fun provideBaseHttpClient( if (NetworkUtilLogger.isRequestLoggingEnabled) { install(KaliumKtorCustomLogging) { - level = LogLevel.ALL + this.level = LogLevel.ALL + this.kaliumLogger = kaliumLogger } } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/NetworkLogger.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/NetworkLogger.kt index 8822bde6c36..8355eb73ecc 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/NetworkLogger.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/NetworkLogger.kt @@ -18,22 +18,12 @@ package com.wire.kalium.network -import co.touchlab.kermit.LogWriter -import com.wire.kalium.logger.KaliumLogLevel import com.wire.kalium.logger.KaliumLogger internal var kaliumLogger = KaliumLogger.disabled() object NetworkLogger { - fun setLoggingLevel(level: KaliumLogLevel, vararg logWriters: LogWriter = arrayOf()) { - kaliumLogger = KaliumLogger( - config = KaliumLogger.Config( - severity = level, - tag = "Network" - ), - logWriters = logWriters - ) + fun init(config: KaliumLogger.Config) { + kaliumLogger = KaliumLogger(config = config, tag = "Network") } - - val isRequestLoggingEnabled: Boolean get() = kaliumLogger.severity in setOf(KaliumLogLevel.VERBOSE, KaliumLogLevel.DEBUG) } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/networkContainer/AuthenticatedNetworkContainerV0.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/networkContainer/AuthenticatedNetworkContainerV0.kt index e00b74ad884..74c4459bd73 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/networkContainer/AuthenticatedNetworkContainerV0.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/networkContainer/AuthenticatedNetworkContainerV0.kt @@ -18,6 +18,7 @@ package com.wire.kalium.network.api.v0.authenticated.networkContainer +import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.NetworkStateObserver import com.wire.kalium.network.api.base.authenticated.AccessTokenApi import com.wire.kalium.network.api.base.authenticated.CallApi @@ -73,6 +74,7 @@ internal class AuthenticatedNetworkContainerV0 internal constructor( private val sessionManager: SessionManager, certificatePinning: CertificatePinning, mockEngine: HttpClientEngine?, + kaliumLogger: KaliumLogger, engine: HttpClientEngine = mockEngine ?: defaultHttpEngine( serverConfigDTOApiProxy = sessionManager.serverConfig().links.apiProxy, proxyCredentials = sessionManager.proxyCredentials(), @@ -80,10 +82,11 @@ internal class AuthenticatedNetworkContainerV0 internal constructor( ) ) : AuthenticatedNetworkContainer, AuthenticatedHttpClientProvider by AuthenticatedHttpClientProviderImpl( - sessionManager, - networkStateObserver, - { httpClient -> AccessTokenApiV0(httpClient) }, - engine + sessionManager = sessionManager, + networkStateObserver = networkStateObserver, + accessTokenApi = { httpClient -> AccessTokenApiV0(httpClient) }, + engine = engine, + kaliumLogger = kaliumLogger ) { override val accessTokenApi: AccessTokenApi get() = AccessTokenApiV0(networkClient.httpClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/networkContainer/AuthenticatedNetworkContainerV2.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/networkContainer/AuthenticatedNetworkContainerV2.kt index 932d102011f..43eaca51747 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/networkContainer/AuthenticatedNetworkContainerV2.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/networkContainer/AuthenticatedNetworkContainerV2.kt @@ -18,6 +18,7 @@ package com.wire.kalium.network.api.v2.authenticated.networkContainer +import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.NetworkStateObserver import com.wire.kalium.network.api.v2.authenticated.E2EIApiV2 import com.wire.kalium.network.api.base.authenticated.AccessTokenApi @@ -69,22 +70,26 @@ import com.wire.kalium.network.session.CertificatePinning import com.wire.kalium.network.session.SessionManager import io.ktor.client.engine.HttpClientEngine +@Suppress("LongParameterList") internal class AuthenticatedNetworkContainerV2 internal constructor( private val networkStateObserver: NetworkStateObserver, private val sessionManager: SessionManager, private val selfUserId: UserId, certificatePinning: CertificatePinning, mockEngine: HttpClientEngine?, + kaliumLogger: KaliumLogger, engine: HttpClientEngine = mockEngine ?: defaultHttpEngine( - sessionManager.serverConfig().links.apiProxy, + serverConfigDTOApiProxy = sessionManager.serverConfig().links.apiProxy, + proxyCredentials = sessionManager.proxyCredentials(), certificatePinning = certificatePinning ) ) : AuthenticatedNetworkContainer, AuthenticatedHttpClientProvider by AuthenticatedHttpClientProviderImpl( - sessionManager, - networkStateObserver, - { httpClient -> AccessTokenApiV2(httpClient) }, - engine + sessionManager = sessionManager, + networkStateObserver = networkStateObserver, + accessTokenApi = { httpClient -> AccessTokenApiV2(httpClient) }, + engine = engine, + kaliumLogger = kaliumLogger ) { override val accessTokenApi: AccessTokenApi get() = AccessTokenApiV2(networkClient.httpClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/networkContainer/AuthenticatedNetworkContainerV3.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/networkContainer/AuthenticatedNetworkContainerV3.kt index 9cb423f5077..76217580ad6 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/networkContainer/AuthenticatedNetworkContainerV3.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/networkContainer/AuthenticatedNetworkContainerV3.kt @@ -18,6 +18,7 @@ package com.wire.kalium.network.api.v3.authenticated.networkContainer +import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.NetworkStateObserver import com.wire.kalium.network.api.base.authenticated.AccessTokenApi import com.wire.kalium.network.api.base.authenticated.CallApi @@ -70,12 +71,14 @@ import com.wire.kalium.network.session.CertificatePinning import com.wire.kalium.network.session.SessionManager import io.ktor.client.engine.HttpClientEngine +@Suppress("LongParameterList") internal class AuthenticatedNetworkContainerV3 internal constructor( private val networkStateObserver: NetworkStateObserver, private val sessionManager: SessionManager, private val selfUserId: UserId, certificatePinning: CertificatePinning, mockEngine: HttpClientEngine?, + kaliumLogger: KaliumLogger, engine: HttpClientEngine = mockEngine ?: defaultHttpEngine( serverConfigDTOApiProxy = sessionManager.serverConfig().links.apiProxy, proxyCredentials = sessionManager.proxyCredentials(), @@ -83,10 +86,11 @@ internal class AuthenticatedNetworkContainerV3 internal constructor( ) ) : AuthenticatedNetworkContainer, AuthenticatedHttpClientProvider by AuthenticatedHttpClientProviderImpl( - sessionManager, - networkStateObserver, - { httpClient -> AccessTokenApiV3(httpClient) }, - engine + sessionManager = sessionManager, + networkStateObserver = networkStateObserver, + accessTokenApi = { httpClient -> AccessTokenApiV3(httpClient) }, + engine = engine, + kaliumLogger = kaliumLogger ) { override val accessTokenApi: AccessTokenApi get() = AccessTokenApiV3(networkClient.httpClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/networkContainer/AuthenticatedNetworkContainerV4.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/networkContainer/AuthenticatedNetworkContainerV4.kt index 6e0b002ead3..03673d834da 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/networkContainer/AuthenticatedNetworkContainerV4.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/networkContainer/AuthenticatedNetworkContainerV4.kt @@ -18,6 +18,7 @@ package com.wire.kalium.network.api.v4.authenticated.networkContainer +import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.NetworkStateObserver import com.wire.kalium.network.api.base.authenticated.AccessTokenApi import com.wire.kalium.network.api.base.authenticated.CallApi @@ -69,12 +70,14 @@ import com.wire.kalium.network.session.CertificatePinning import com.wire.kalium.network.session.SessionManager import io.ktor.client.engine.HttpClientEngine +@Suppress("LongParameterList") internal class AuthenticatedNetworkContainerV4 internal constructor( private val networkStateObserver: NetworkStateObserver, private val sessionManager: SessionManager, private val selfUserId: UserId, certificatePinning: CertificatePinning, mockEngine: HttpClientEngine?, + kaliumLogger: KaliumLogger, engine: HttpClientEngine = mockEngine ?: defaultHttpEngine( serverConfigDTOApiProxy = sessionManager.serverConfig().links.apiProxy, proxyCredentials = sessionManager.proxyCredentials(), @@ -82,10 +85,11 @@ internal class AuthenticatedNetworkContainerV4 internal constructor( ) ) : AuthenticatedNetworkContainer, AuthenticatedHttpClientProvider by AuthenticatedHttpClientProviderImpl( - sessionManager, - networkStateObserver, - { httpClient -> AccessTokenApiV4(httpClient) }, - engine + sessionManager = sessionManager, + networkStateObserver = networkStateObserver, + accessTokenApi = { httpClient -> AccessTokenApiV4(httpClient) }, + engine = engine, + kaliumLogger = kaliumLogger ) { override val accessTokenApi: AccessTokenApi get() = AccessTokenApiV4(networkClient.httpClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/networkContainer/AuthenticatedNetworkContainerV5.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/networkContainer/AuthenticatedNetworkContainerV5.kt index c6a9f3df2a0..4bcdc9af967 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/networkContainer/AuthenticatedNetworkContainerV5.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/networkContainer/AuthenticatedNetworkContainerV5.kt @@ -18,6 +18,7 @@ package com.wire.kalium.network.api.v5.authenticated.networkContainer +import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.NetworkStateObserver import com.wire.kalium.network.api.base.authenticated.AccessTokenApi import com.wire.kalium.network.api.base.authenticated.CallApi @@ -69,12 +70,14 @@ import com.wire.kalium.network.session.CertificatePinning import com.wire.kalium.network.session.SessionManager import io.ktor.client.engine.HttpClientEngine +@Suppress("LongParameterList") internal class AuthenticatedNetworkContainerV5 internal constructor( private val networkStateObserver: NetworkStateObserver, private val sessionManager: SessionManager, private val selfUserId: UserId, certificatePinning: CertificatePinning, mockEngine: HttpClientEngine?, + kaliumLogger: KaliumLogger, engine: HttpClientEngine = mockEngine ?: defaultHttpEngine( serverConfigDTOApiProxy = sessionManager.serverConfig().links.apiProxy, proxyCredentials = sessionManager.proxyCredentials(), @@ -82,10 +85,11 @@ internal class AuthenticatedNetworkContainerV5 internal constructor( ) ) : AuthenticatedNetworkContainer, AuthenticatedHttpClientProvider by AuthenticatedHttpClientProviderImpl( - sessionManager, - networkStateObserver, - { httpClient -> AccessTokenApiV5(httpClient) }, - engine + sessionManager = sessionManager, + networkStateObserver = networkStateObserver, + accessTokenApi = { httpClient -> AccessTokenApiV5(httpClient) }, + engine = engine, + kaliumLogger = kaliumLogger ) { override val accessTokenApi: AccessTokenApi get() = AccessTokenApiV5(networkClient.httpClient) diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt index 23cf78dc3b5..b39e6a06500 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt @@ -18,6 +18,7 @@ package com.wire.kalium.network.networkContainer +import com.wire.kalium.logger.KaliumLogger import com.wire.kalium.network.AuthenticatedNetworkClient import com.wire.kalium.network.AuthenticatedWebSocketClient import com.wire.kalium.network.NetworkStateObserver @@ -114,7 +115,8 @@ interface AuthenticatedNetworkContainer { selfUserId: UserId, userAgent: String, certificatePinning: CertificatePinning, - mockEngine: HttpClientEngine? + mockEngine: HttpClientEngine?, + kaliumLogger: KaliumLogger, ): AuthenticatedNetworkContainer { KaliumUserAgentProvider.setUserAgent(userAgent) @@ -124,14 +126,16 @@ interface AuthenticatedNetworkContainer { networkStateObserver, sessionManager, certificatePinning, - mockEngine + mockEngine, + kaliumLogger, ) 1 -> AuthenticatedNetworkContainerV0( networkStateObserver, sessionManager, certificatePinning, - mockEngine + mockEngine, + kaliumLogger, ) 2 -> AuthenticatedNetworkContainerV2( @@ -139,7 +143,8 @@ interface AuthenticatedNetworkContainer { sessionManager, selfUserId, certificatePinning, - mockEngine + mockEngine, + kaliumLogger, ) 3 -> AuthenticatedNetworkContainerV3( @@ -147,7 +152,8 @@ interface AuthenticatedNetworkContainer { sessionManager, selfUserId, certificatePinning, - mockEngine + mockEngine, + kaliumLogger, ) 4 -> AuthenticatedNetworkContainerV4( @@ -155,7 +161,8 @@ interface AuthenticatedNetworkContainer { sessionManager, selfUserId, certificatePinning, - mockEngine + mockEngine, + kaliumLogger, ) 5 -> AuthenticatedNetworkContainerV5( @@ -163,7 +170,8 @@ interface AuthenticatedNetworkContainer { sessionManager, selfUserId, certificatePinning, - mockEngine + mockEngine, + kaliumLogger, ) else -> error("Unsupported version: $version") @@ -184,7 +192,8 @@ internal class AuthenticatedHttpClientProviderImpl( private val sessionManager: SessionManager, private val networkStateObserver: NetworkStateObserver, private val accessTokenApi: (httpClient: HttpClient) -> AccessTokenApi, - private val engine: HttpClientEngine + private val engine: HttpClientEngine, + private val kaliumLogger: KaliumLogger, ) : AuthenticatedHttpClientProvider { override suspend fun clearCachedToken() { @@ -212,7 +221,8 @@ internal class AuthenticatedHttpClientProviderImpl( networkStateObserver, engine, sessionManager.serverConfig(), - bearerAuthProvider + bearerAuthProvider, + kaliumLogger ) } override val websocketClient by lazy { @@ -220,7 +230,8 @@ internal class AuthenticatedHttpClientProviderImpl( networkStateObserver, engine, bearerAuthProvider, - sessionManager.serverConfig() + sessionManager.serverConfig(), + kaliumLogger ) } override val networkClientWithoutCompression by lazy { @@ -229,6 +240,7 @@ internal class AuthenticatedHttpClientProviderImpl( engine, sessionManager.serverConfig(), bearerAuthProvider, + kaliumLogger, installCompression = false ) } diff --git a/network/src/commonTest/kotlin/com/wire/kalium/api/ApiTest.kt b/network/src/commonTest/kotlin/com/wire/kalium/api/ApiTest.kt index 936c6328297..f102edf2827 100644 --- a/network/src/commonTest/kotlin/com/wire/kalium/api/ApiTest.kt +++ b/network/src/commonTest/kotlin/com/wire/kalium/api/ApiTest.kt @@ -27,6 +27,7 @@ import com.wire.kalium.network.UnboundNetworkClient import com.wire.kalium.network.api.v0.authenticated.AccessTokenApiV0 import com.wire.kalium.network.api.v0.authenticated.networkContainer.AuthenticatedNetworkContainerV0 import com.wire.kalium.network.api.v0.unauthenticated.networkContainer.UnauthenticatedNetworkContainerV0 +import com.wire.kalium.network.kaliumLogger import com.wire.kalium.network.networkContainer.KaliumUserAgentProvider import com.wire.kalium.network.serialization.JoseJson import com.wire.kalium.network.serialization.XProtoBuf @@ -114,7 +115,8 @@ internal abstract class ApiTest { sessionManager = TEST_SESSION_MANAGER, networkStateObserver = networkStateObserver, certificatePinning = emptyMap(), - mockEngine = null + mockEngine = null, + kaliumLogger = kaliumLogger ).networkClient } @@ -129,7 +131,8 @@ internal abstract class ApiTest { sessionManager = TEST_SESSION_MANAGER, networkStateObserver = networkStateObserver, certificatePinning = emptyMap(), - mockEngine = null + mockEngine = null, + kaliumLogger = kaliumLogger ).websocketClient } @@ -146,7 +149,8 @@ internal abstract class ApiTest { engine = mockEngine, serverConfigDTO = TEST_SESSION_MANAGER.serverConfig(), bearerAuthProvider = TEST_BEARER_AUTH_PROVIDER, - networkStateObserver = networkStateObserver + networkStateObserver = networkStateObserver, + kaliumLogger = kaliumLogger ) } @@ -254,7 +258,8 @@ internal abstract class ApiTest { sessionManager = TEST_SESSION_MANAGER, networkStateObserver = networkStateObserver, certificatePinning = emptyMap(), - mockEngine = null + mockEngine = null, + kaliumLogger = kaliumLogger ).networkClient } diff --git a/network/src/commonTest/kotlin/com/wire/kalium/api/common/SessionManagerTest.kt b/network/src/commonTest/kotlin/com/wire/kalium/api/common/SessionManagerTest.kt index 1995b563a52..93e3d53ced7 100644 --- a/network/src/commonTest/kotlin/com/wire/kalium/api/common/SessionManagerTest.kt +++ b/network/src/commonTest/kotlin/com/wire/kalium/api/common/SessionManagerTest.kt @@ -29,6 +29,7 @@ import com.wire.kalium.network.api.base.model.RefreshTokenDTO import com.wire.kalium.network.api.base.model.SessionDTO import com.wire.kalium.network.api.v0.authenticated.AccessTokenApiV0 import com.wire.kalium.network.api.v0.authenticated.AssetApiV0 +import com.wire.kalium.network.kaliumLogger import com.wire.kalium.network.networkContainer.KaliumUserAgentProvider import com.wire.kalium.network.session.SessionManager import com.wire.kalium.network.session.installAuth @@ -168,7 +169,7 @@ class SessionManagerTest { } val client = AuthenticatedNetworkClient( - DEFAULT_TEST_NETWORK_STATE_OBSERVER, mockEngine, sessionManager.serverConfig(), bearerAuthProvider, false + DEFAULT_TEST_NETWORK_STATE_OBSERVER, mockEngine, sessionManager.serverConfig(), bearerAuthProvider, kaliumLogger, false ) val assetApi = AssetApiV0(client) val kaliumFileSystem: FileSystem = FakeFileSystem() diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/PersistenceLogger.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/PersistenceLogger.kt index e43e9bfb2be..74201bdce11 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/PersistenceLogger.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/PersistenceLogger.kt @@ -18,20 +18,12 @@ package com.wire.kalium.persistence -import co.touchlab.kermit.LogWriter -import com.wire.kalium.logger.KaliumLogLevel import com.wire.kalium.logger.KaliumLogger internal var kaliumLogger = KaliumLogger.disabled() object PersistenceLogger { - fun setLoggingLevel(level: KaliumLogLevel, vararg logWriters: LogWriter = arrayOf()) { - kaliumLogger = KaliumLogger( - config = KaliumLogger.Config( - severity = level, - tag = "Persistence" - ), - logWriters = logWriters - ) + fun init(config: KaliumLogger.Config) { + kaliumLogger = KaliumLogger(config = config, tag = "Persistence") } }