Log4j – XML based configuration

Log4j – XML configuration example

Steps 1) Create Maven project

Follow this post to create maven project and configure Log4j

Steps 2) Create log4j.xml file

Create log4j.xml file put inside src/main/resources package and add below content. For this example, I’m taking RollingFileAppender. Which means all the logs can be seen in generated log file.

 

 

Step 3) Create Log4jXmlConfigTest.java

Create a class inside src/main/java package and add logging statements over there

Step 4) Execute the program

Right, click and run as a java program. Since we have chosen RollingFileAppender, You should be able to see a xmlConfig file created with .log extension in projects root folder with below log.

Output:-

 

 

Leave a Reply

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