Getting log4j to work is way more complicated than advertised. I keep getting this error:
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
I have tried to put my
log4j.xml file all over the place, but what I want it is to have it in my
/resources folder. In my
pom.xml, these paths are defined:
... long list of plugins coming, let's cut it off.
All resources that are in the
resources directory are accessible from the
.jar. There are images and icons, all working. But Log4j ignores the configuration file.
So how can I tell it where the file is and finally start actually learning to use it?
Best How To :
You are using
log4j2 - which requires a
Just rename the file, place it in the resource folder (or anywhere else in the classpath) and it should work.
Alternatevly, you can take a look at the documentation:
- Log4j will inspect the "log4j.configurationFile" system property and, if set, will attempt to load the configuration using the ConfigurationFactory that matches the file extension.
- If no system property is set the YAML ConfigurationFactory will look for log4j2-test.yaml or log4j2-test.yml in the classpath.
- If no such file is found the JSON ConfigurationFactory will look for log4j2-test.json or log4j2-test.jsn in the classpath.
- If no such file is found the XML ConfigurationFactory will look for log4j2-test.xml in the classpath.
- If a test file cannot be located the YAML ConfigurationFactory will look for log4j2.yaml or log4j2.yml on the classpath.
- If a YAML file cannot be located the JSON ConfigurationFactory will look for log4j2.json or log4j2.jsn on the classpath.
- If a JSON file cannot be located the XML ConfigurationFactory will try to locate log4j2.xml on the classpath.
- If no configuration file could be located the DefaultConfiguration will be used. This will cause logging output to go to the console.
Note, however, that the log4j2 xml-configuration also has a different syntax than version 1.