是否有一种简单的方法可以将相同的代码基础用于:
android.util.Log
登录 android(以登录 Logcat)
对于另一个编译但使用相同的代码(以某种通用方法)类似于:
genericlog.i("myinfo")
--> 在 android 上转换为:Log.i("myinfo")
//for logcat
并为win编译
genericlog.i("myinfo")
--> 在窗口上转换为:whatever-log-framework.info("myinfo")
已配置 :-)
答案 0 :(得分:1)
答案 1 :(得分:1)
好的,我的解决方案是使用 https://github.com/MicroUtils/kotlin-logging。
安卓依赖
implementation 'io.github.microutils:kotlin-logging:2.0.4'
implementation 'org.slf4j:slf4j-android:1.7.21'
windows 的依赖
implementation("io.github.microutils:kotlin-logging-jvm:2.0.2")
implementation("org.slf4j:slf4j-api:1.7.30")
有了这个,我可以在“通用”代码中使用相同的日志结构。
private val log = KotlinLogging.logger {}
log.info{"log it :-)"}