log4j.properties Examples

I don’t find any good example of log4j.properties so adding some log4j properties files.

For tests, the directory src/test/resources is the appropriate location for the log4j.propertiesfile. When Maven starts the tests, this directory will be part of the classpath.

The file needs to go into src/main/resources/ or src/test/resources/ (if you need it only for unit tests).
Longer explanation: Maven splits the Java classpath into source code and resources (non-Java things like property files, images, etc). The main reason for this is that Maven can do filtering of resources for you and to make this extra safe, they put the resources into a different folder than the sources.

1. Output to Console

All logging will be redirected to your console.

2. Output to File

All logging will be redirected to your specified log file.

3. Output to Console and File

All logging will be redirected to both log file and console.

Leave a Reply

Your email address will not be published. Required fields are marked *