Jealous of Timber logging for a plain Java app

I started using timber with timberkt in Android, and it was i { "Very cool." }
It was everything I wanted for prototyping:

  • no worrying about logger instantiation
  • lazy eval of the logging string or lambda
  • very short and clear code.

I’m writing a Kotlin app that runs in plain old JVM (no Android) and I miss Timber. Is there anything that hits those three (tree?) points and would let me d { "easily log stuff?" }

You can always write simple aliases for standard loggers like

fun i(message: String, vararg parameters: Any){

for slf4j.

You do not have to bother with instantiation. Arguments evaluated lazily by default and it does not make sense to evaluate simple string constant in lambda, it just creates unnecessary overhead. The name is one-letter, though I do not recommend it. Call it at least logInfo. Readability is much more important. At the end, you can’t protect forests by writing less letters in the code.

Sure, the “i” vs “logInfo” - either works!

But I did like the idea of an import, then being able to drop logInfo { "some lazy thing" } anywhere and get all the niceness of Timber.

But if there is some simple way to do logging that doesn’t take much 'learnin on my part and lets me not care about the details (calling from main, a class, or inside a companion, because I’m just prototyping) - even better.

you can try to take a look at kotlin-logging, it is not that simple but gives pretty idiomatic logging in kotlin. There is also this question in SO with other possibilities: Idiomatic way of logging in Kotlin - Stack Overflow

That worked great for me, thank you!