Java : Log error messages with Log4j

Posted in Exception Handling By Raj On December 26, 2017

In this article, I am going to cover how to log error messages, here I am using log4j logging framework, first you need to update POM with the below dependency

Step 1:

Step 2:

You need to configure log4j properties, you can use either XML or .properties file, here I am using XML file, you can create properties in the root folder of project

The File property is the log file name 

The project structure is something like this

log4j-example

Step 3:

Load configuration in your class file using DOMConfiguration

You should see below entry in the logfile.log