is there any logging solution for Kotlin able to p...
# announcements
is there any logging solution for Kotlin able to perform a NOP through configuration? I'm currently using SLF4J, with calls like
, so even if I configure the logger to only log errors, the info call will still incur the cost of the expensive operation, with no message being logged. Would be nice to have it so the logging doesn't even happen at all unless I turn it on.
I wonder how it works...
you can also say either
if (logger.isInfoEnabled()) <|>(...)
<|>(...) {}
, but neither are ideal compared to more Kotlin-y solutions like what you found
ah, I think that solution just takes the lambda and doesn't call it if the logging level doesn't match
Log4j2 also has a way to pass methods IIRC. They don't get called unless that logging level is enabled...
I believe there are some libraries that completely compile out if the logging level is configured appropriately, but they're also less configurable
right, I guess I was over thinking it, I was thinking of not even outputting the lambda on the build, but that seems extreme, probably not gonna gain a lot from that
I heard proguard can be used for that kind of thing
☝️ 1
@Emmanuel Oga you asked about return in functions vs not in lambdas before right?
This is a great example of what ultra concise lambdas give you
Basically, lazy parameters :-)
good point
i played with the idea a while ago it seems log4j2 does the same natively
👍 1
Using a lambda syntax does make it so it is not executed when logging is disabled. That is one of the reasons that drove me to writing KmLogging was that I wanted very little overhead when the product is in the field. I needed one that was multiplatform which microutils is not.