ktorio / ktor

Framework for quickly creating connected applications in Kotlin with minimal effort
https://ktor.io
Apache License 2.0
12.97k stars 1.06k forks source link

Support for customising logger (e.g. via project-specific actual) #1081

Closed cosminstefanxp closed 5 years ago

cosminstefanxp commented 5 years ago

Ktor Version

1.1.4

JVM Version, Operating System and Relevant Context

Android

Feedback

Currently, ktor-client-logging works on jvm using an slf4j implementation. It would be great if there would be support for logging using Log on the android platform. We've tried to make an actual implementation in our code base for the Logger.Companion.DEFAULT, but the compiler doesn't allow us as it seems it can't find the expected.

https://github.com/ktorio/ktor/blob/aee7373fb280b605e6486adabd397034a93aa30a/ktor-client/ktor-client-features/ktor-client-logging/jvm/src/io/ktor/client/features/logging/LoggerJvm.kt

e5l commented 5 years ago

Hi @cosminstefanxp, thanks for the report.

Could you use something like that?

Logging {
    logger = object : Logger {
        override fun log(message: String) {
            Log.v(TAG, message)
        }
    }
}
cosminstefanxp commented 5 years ago

Hmmm.. I'm slightly confused. Where would that go in a multiplatform project? Just in the Android project?

e5l commented 5 years ago

Yes, in Android. You also could add the expect class in common:

expect class MyAwesomeLogger : Logger

and add actual implementation for each platform:

actual class MyAwesomeLogger : Logger { ... }
e5l commented 5 years ago

Closed for now. Please reopen if the problem still exists.