Hi All! I am trying to find out if I have found a ...
# kotlin-logging
a
Hi All! I am trying to find out if I have found a bug, or else have just misunderstood something. I'm learning Kotlin and kotlin-logging; I have some code which looks like:
Copy code
import ...
private val logger: KLogger = KotlinLogging.logger {}
internal class Engine(private val di: DI) {
    fun mainMethod(args: Array<String>) { // called from "real" main()
        System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG")
        logger.trace("trace")
        logger.debug("debug")
        <http://logger.info|logger.info>("info")
        logger.warn("warning")
        logger.error("error")
...and when it runs, it is (sensibly) printing:
Copy code
[main] DEBUG psm.Engine - debug
[main] INFO psm.Engine - info
[main] WARN psm.Engine - warning
[main] ERROR psm.Engine - error
HOWEVER: as soon as I declare another
logger: KLogger = KotlinLogging.logger {}
in another classfile in the same package, the behaviour *changes*; more in comments:
When there are 2+ logger instances defined, the app snaps back to just printing
Copy code
[main] INFO psm.Engine - info
[main] WARN psm.Engine - warning
[main] ERROR psm.Engine - error
So I am wondering whether the second instance is stomping on the
DEFAULT_LOG_LEVEL_KEY
property? And if so, what's the proper way to set that value at runtime, please?
Method of setting log level is described on this page as linked-to from this page
o
did you try setting the properties on startup
a
Hi @oshai ! I did not, because that's not what I want to do. I want it dynamically controllable from the app, rather than being a JVM setting.
This could include, for instance, switching DEBUG logging on and off via a REST API
o
I am not sure it's possible with simple logger. try log4j or logback
👍 1