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

Not work on Android

Open alessandroToninelli opened this issue 3 years ago • 9 comments

implementation 'io.github.microutils:kotlin-logging:2.0.11' implementation 'org.slf4j:slf4j-simple:1.7.36' implementation 'org.slf4j:slf4j-api:1.7.36'

With these library i can't see any log using Android

val klog = KotlinLogging.logger{}

alessandroToninelli avatar Jul 08 '22 12:07 alessandroToninelli

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

github-actions[bot] avatar Jul 08 '22 12:07 github-actions[bot]

Try using the dependency io.github.microutils:kotlin-logging-jvm instead of the first one (note the jvm at the beginning). And you should also use slf4j-android and not slf4j-simple probably.

oshai avatar Jul 08 '22 14:07 oshai

Same, not work with slf4j-android and kotlin-logging-jvm

alessandroToninelli avatar Jul 08 '22 14:07 alessandroToninelli

There is this example which was working in the past (but it uses the old kotlin-logging 1.x): https://github.com/MicroUtils/kotlin-logging-example-android

You can try that or spot the differences or create a newer repo to reproduce the issue.

oshai avatar Jul 08 '22 14:07 oshai

i've already use this example but it still not work. the combination of libraries from that example does not work

alessandroToninelli avatar Jul 08 '22 15:07 alessandroToninelli

I am using it all the time on desktop and Android and it works. For Android just use the dependencies:

implementation("io.github.microutils:kotlin-logging-jvm:2.1.23")
implementation("org.slf4j:slf4j-android:1.7.35")

mipastgt avatar Jul 13 '22 09:07 mipastgt

Not work

at this point it makes me think that I am doing something else wrong besides the dependencies

i declared a global variable in a file called KLogger.Kt like this:

val klog = KotlinLogging.logger {  }

alessandroToninelli avatar Jul 13 '22 09:07 alessandroToninelli

This is not the intended usage. First try to follow the examples before you make your own experiments.

mipastgt avatar Jul 13 '22 10:07 mipastgt

not the correct use?? tell me what changes at runtime my example from the one shown at the link https://github.com/MicroUtils/kotlin-logging-example-android/blob/master/app/src/main/java/mu/kotlinloggingexampleandroid/MainActivity.kt . And anyway using the examples shown on the page doesn't work.

alessandroToninelli avatar Jul 13 '22 12:07 alessandroToninelli

were you able to resolve the issue or still need assistance?

oshai avatar Oct 29 '22 17:10 oshai

here it is suggested to use slf4j-handroid.

oshai avatar Oct 29 '22 17:10 oshai

我一直在台式机和Android上使用它,并且可以正常工作。 对于Android,只需要使用依赖项:

implementation("io.github.microutils:kotlin-logging-jvm:2.1.23")
implementation("org.slf4j:slf4j-android:1.7.35")

Thanks, I can print out the log with yours

wuxianggujun avatar Dec 11 '22 13:12 wuxianggujun

This is my previous configuration and can't print logs at all // implementation 'org.slf4j:slf4j-android:1.7.36' //implementation 'io.github.microutils:kotlin-logging-jvm:3.0.2'

wuxianggujun avatar Dec 11 '22 13:12 wuxianggujun

kotlin logging 3 is not compatible with slf4j 1.7. it seems that slf4j-android doesn't have 2.x versions so I suspect it's not working anymore. Try to find another implementation for slf4j 2 for android.

oshai avatar Dec 13 '22 07:12 oshai

See updates on #122 on how I plan to solve the issue.

oshai avatar Dec 16 '22 07:12 oshai

Version 4.0.0-beta-15 contains native android logging with artifact kotlin-logging-android.

oshai avatar Feb 11 '23 22:02 oshai