Search code examples
javakotlinlog4jruntime-error

Programmatically Configuring Log4J From Kotlin


I have a project that uses Log4J for logging, and I wish to programmatically configure Log4J from a Kotlin file rather than via an XML file or properties, but Log4J doesn't seem to be able to find the class file on runtime. I ported the code to Java and made a simple test in there, and it worked okay. Is it perhaps something the Kotlin compiler is doing to the class when it creates it that causes Log4J to miss it when scanning? Any help would be greatly appreciated.

My code: https://hastebin.com/vepekezoqe.kotlin

Note: I tried setting breakpoints in both projects right after the getConfiguration() call, and the Kotlin version was not hit while the Java version was, which confirms that Log4J indeed didn't find the class.


Solution

  • Thanks for the helpful comments, guys. I was not aware that this was an ongoing issue. I have since mitigated it by dual-compiling Java and Kotlin in the project. Will close this once SO allows me to answer my own question.