Add log4j to your project
This is a quick guide to add log4j to your project. The steps to how add the log4j jar to the project are explained here http://mkaroune.e-monsite.com/pages/add-jar-to-lib-folder-eclipse.html.
Next we will create the log4j.xml file to configure the log4j library to our requirements.This file will define the 3 core objects.
- Appender: It is responsible of writing data to Console, file or database.
- Layout: It defines how the log message is formatted.
- Logger: It is responsible for collecting the data that will be logged in Console for example (Appender) with the format defined in the Layout.
Following is a simple example of log4j properties file. Here we are defining a Consoler appender and layout pattern. Then we are mapping all the DEBUG level messages from the application to the ConsoleAppender.
//Logging examples logger.debug("Getting properties from the config files"); logger.error("No file found");