oshai / kotlin-logging

Lightweight Multiplatform logging framework for Kotlin. A convenient and performant logging facade.
Other
2.66k stars 113 forks source link

Problems regarding Android #359

Open mahozad opened 1 year ago

mahozad commented 1 year ago

I'm using the library like this in my single-platform Android project:

build.gradle.kts

dependencies {
  implementation("io.github.oshai:kotlin-logging-android:5.1.0")
  implementation("org.slf4j:slf4j-android:1.7.36")
  testImplementation("org.slf4j:slf4j-simple:2.0.9")
  // ...
}

src/test/resources/simplelogger.properties:

# See https://stackoverflow.com/q/14544991/8583692
# and https://www.slf4j.org/api/org/slf4j/simple/SimpleLogger.html
org.slf4j.simpleLogger.logFile=System.out
org.slf4j.simpleLogger.defaultLogLevel=debug

It seems to be working fine for the most part. But there are some problems

First, the workaround above had not been mentioned anywhere. I added testImplementation("org.slf4j:slf4j-simple:2.0.9") to prevent my unit tests from failing. It is also a little bit cleaner in my opinion than using the following:

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

And how about adding a section in the README of this repository for how to use the library in Android (and possibly other platforms)? Or at least, adding links to the example repositories?

The next problem is, there is no slf4j-android version 2 (as shown above) and it makes me a little uncomfortable. It seems that SLF4J dropped the android module (see section April 7th, 2017 - Release of SLF4J 1.8.0-alpha0 in the release notes) apparently because of lack of interest from users.

Would you mind please opening an issue in SLF4j repository or issue tracker and request the android module to be brought back?

Another problem is that my integration tests are failing for some reason:

~~Unknown platform error occurred when running the UTP test suite. Please check logs for details. com.android.ddmlib.TimeoutException~~

~~It's probably an ADB problem? (the problem also existed when I checked out my previous git commits that had not included kotlin-logging library and they also failed)~~

github-actions[bot] commented 1 year ago

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

oshai commented 1 year ago

Thanks, I will see how to improve docs. If you have a cocrete idea a PR is welcome.

mahozad commented 1 year ago

Thank you.

CXwudi commented 1 month ago

There is an alternative fork of slf4j-android in https://github.com/nomis/slf4j-android, supports SLF4J 2.x