I must be doing something stupid, but I can't find it. I'm trying to add Log4j to my project, but it isn't reading the properties file. I have created a minimal workable example project. In IntelliJ, I created a new gradle project. I added log4j and added a main class.
Here is the project structure.
.
├── build.gradle
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
├── main
│ ├── java
│ │ └── Main.java
│ └── resources
│ └── log4j.properties
└── test
├── java
└── resources
build.gradle
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.13.3'
}
log4j.properties
log4j.rootLogger=TRACE
Main.java
import org.apache.logging.log4j.LogManager;
public class Main {
public static void main(String[] args) {
System.out.println("Print");
System.out.println("Root Logger Level: " + LogManager.getRootLogger().getLevel());
}
}
When I run this, the output says that the root logger's level is "ERROR", even though I'm setting it to trace. Of course this means that any log statements below error level are not printed.
Print
Root Logger Level: ERROR
Every piece of documentation I read says that the properties file needs to be in a directory on the classpath, which makes sense. According to the gradle documentation and my own investigation, the resources directory is on the classpath. Experimentally, I have tried placing the file at every level of the hierarchy with no difference. I can't see any reason why the properties file isn't being found.
I tried specifying it directly by adding -Dlog4j.configuration=<full/path/to/properties>
to the VM arguments. This still didn't work, but gradle gives me the following output:
BUILD SUCCESSFUL in 748ms
3 actionable tasks: 1 executed, 2 up-to-date
ERROR StatusLogger Reconfiguration failed: No configuration found for '2a139a55' at 'null' in 'null'
10:23:30 PM: Task execution finished 'Main.main()'.
This appears to happen after the program has terminated. I'm not sure if it's related.
I must be missing something stupid, but I can't find anything. I've looked at dozens of examples and it seems like I'm doing everything right. What am I missing?