kotlin-logging icon indicating copy to clipboard operation
kotlin-logging copied to clipboard

Logging not appearing in LogCat KMM Compose

Open ErickSorto opened this issue 11 months ago • 8 comments

Hello I integrated kotlin-logging into my project but when I use the logger in my classes nothing appear in LogCat.

Code in common:

val logger = KotlinLogging.logger {}

@Composable
@Preview
fun App(
    onSplashFinished: () -> Unit = {}
) {
    logger.debug { "Testing!" }
    AppTheme {
            Surface(
                modifier = Modifier.fillMaxSize(),
                color = Color.Transparent
            ) {
                val navController = rememberNavController()
                //  val screen by splashViewModel.state
                MainGraph(
                    navController = navController,
                    onDataLoaded = onSplashFinished
                )
            }
    }
}

Nothing appears in LogCat. I added this to common dependencies in my KMM Compose project:

kotlinLogging = "7.0.3"

kotlin-logging = { module = "io.github.oshai:kotlin-logging", version.ref = "kotlinLogging" }

ErickSorto avatar Jan 17 '25 16:01 ErickSorto

Thank you for reporting an issue. See the wiki for documentation and slack for questions.

github-actions[bot] avatar Jan 17 '25 16:01 github-actions[bot]

Maybe you need to place a simplelogger.properties in your resources directory if you are using org.slf4j:slf4j-simple. See here: How to configure slf4j-simple

zerofancy avatar Jan 18 '25 16:01 zerofancy

Would this be in Shared Resource or Android Resource?

ErickSorto avatar Jan 19 '25 01:01 ErickSorto

Any update on the issue?

oshai avatar Apr 16 '25 12:04 oshai

I have the same problem

wying111 avatar Jun 21 '25 14:06 wying111

Did you try logging other levels like error?

Have you tried following https://github.com/oshai/kotlin-logging/wiki/Multiplatform-support#android-usage ?

oshai avatar Aug 12 '25 05:08 oshai

Similar problem here :

I work on a library for android with "com.android.kotlin.multiplatform.library" plugin. I managed to run deviceTests with

  withDeviceTestBuilder { }.configure {
            instrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
            packaging {
                resources.excludes.add("META-INF/*")
            }
        }

however i don't get any debug logs.

    @Test
    fun testLogging(){
        logger.debug { "kt debug" }
        logger.error { "kt error" }
        Log.d("android", "DEBUG")
    }

for example gives: 08-25 15:40:52.802 18717 18734 E CENSORED: kt error 08-25 15:40:52.802 18717 18734 D android : DEBUG

so kotlin logging works but debug level is filtered.

tried

object Static {
    init {
        System.setProperty("kotlin-logging-to-android-native", "true")
    }
}
private val static = Static

in @BeforeTest and in my classes, with no luck

florian-otto avatar Aug 25 '25 13:08 florian-otto

never mind - just had to find the right place for config.properties of https://github.com/nomis/slf4j-android

which is

src/androidDeviceTest/resources/uk/uuid/slf4j/android/config.properties

entry there is: level=DEBUG

now i got my logs

--

florian-otto avatar Aug 25 '25 15:08 florian-otto