https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
s

spierce7

01/17/2021, 5:14 AM
What’s the best multiplatform logging solution that people are using? One of the things I always enjoyed about
Timber
is that you could swap out the actual logging implementation so that you could route all logs into something like Crashlytics.
a

aleksey.tomin

01/17/2021, 5:17 AM
It depends on the targets. If You have to works with native - I suggest to use https://github.com/MicroUtils/kotlin-logging or https://github.com/touchlab/Kermit I know nothing about JS target
j

jw

01/17/2021, 5:23 AM
I keep meaning to finish Timber 5 which is MPP, but it's just not a huge priority
😍 21
I use a snapshot in a MPP app, but I wouldn't recommend that
e

edenman

01/17/2021, 5:30 AM
I have this, in anticipation of Timber 5:
Copy code
expect object Timber {
  fun e(message: String)
  fun e(t: Throwable, message: String)
  fun w(message: String)
  fun w(t: Throwable, message: String)
  fun d(message: String)
  fun v(message: String)
}
but i don’t actually have a web/iOS impl yet so
j

jw

01/17/2021, 5:31 AM
Those are really, really easy. You just forward to
console and NSLog what the fuck Slack you had one job...
😂 15
a

alex009

01/17/2021, 6:50 AM
https://github.com/AAkira/Napier is very similar to timber and allow swap logger implementation
On https://libs.kmp.icerock.dev/ available 9 log libs (category logging)
a

aleksey.tomin

01/17/2021, 7:00 AM
Oh… kotlin-logging has no androidJvm. I’ve forget it. We have androidJvm target and use kermit.
j

John O'Reilly

01/17/2021, 8:39 AM
Have used https://github.com/touchlab/Kermit in a few projects but haven't done comparison in a while on what else is available
r

Reed Ellsworth

02/02/2021, 5:11 AM
For Kotlin Multiplaform logging I could not find a library that had all the features I needed so I ended up writing one. Please check out KmLogging. The features it implements is: • Uses platform specific logging on each platform: Log on Android, os_log on iOS, and console on JavaScript. • High performance. Only 1 boolean check when disabled. I like to put in lots of logging and want all of it turned off for release builds and do not want to pay much overhead for having lots of logging. Also, when logging is on it needs to be really performant. • Extensible. Need to be able add other loggers such as logging to Crashlytics, etc. • Each logger can log at a different level. For example, you may only want info and above going to Crashlytics and all other loggers disabled in production.
1252 Views