I built a fresh IntelliJ project with Gradle and the Kotlin DSL build script, only Kotlin (Java) and java version 10.0.2 as project SDK.
I added the dependencies for log4j into build.gradle.kts:
compile("org.apache.logging.log4j:log4j-api:2.11.1")
compile("org.apache.logging.log4j:log4j-core:2.11.1")
And I put a log4j2.yaml file into /src/main/resources with some configuration.
When I now run this test program:
import org.apache.logging.log4j.LogManager
fun main(args: Array<String>) {
val logger = LogManager.getLogger()!!
logger.warn("Warn")
logger.info("Info")
logger.debug("Debug")
}
I do not get logging output but this message
ERROR StatusLogger No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging. See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2
How do I get log4j2 to work?
Here's what I've done so far:
- I checked that the log4j2 config is copied to the build directory and included in the classpath
- I successfully read the resource file via
classloader.getResource("log4j2.yaml");
- I tried an xml config file instead