Log4j Properties

LOG4j is a simple and flexible logging framework. While developing any framework logging is must needed to track all the events at runtime and this will help further testers to debug the application logs and take some valuable decision's.

The most common configuration options are in practice industry wide i.e. using  log4j.properties configuration.
This this post, I am showing the example code for configuring log4j using log4j.properties file.
Step 1 : Download the log4j JAR : http://www.apache.org/dyn/closer.cgi/logging/log4j/1.2.17/log4j-1.2.17.zip   Click on zip link and store in your local disk, and later unzip the same. 

Step 2 : In eclipse create a new project(as log4jDemo) and with package com.log and also make sure that point the log4j.jar in class path




Step 3 : Create log4j property file as show : make sure this is under src folder 


#Application Log
log4j.logger.devpinoyLogger=DEBUG, dest1
log4j.appender.dest1=org.apache.log4j.FileAppender
log4j.appender.dest1.maxFileSize=900KB
log4j.appender.dest1.maxBackupIndex=6
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
log4j.appender.dest1.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %c %m%n
log4j.appender.dest1.File=/youtprojectpath/src/com/log/Application.log
log4j.appender.dest1.Append=false


Please see the snapshot for the same 




Step 4 : Create a simple class called Log4jLogging under com.log package 




Step 5 : Right click and run the Log4jLogging.class file 



Step 6 : Should create a file called Application.log as path set in the log4j property file and output would look like this.

Application.log 

18/02/2016 09:50:48 devpinoyLogger logging test
18/02/2016 09:50:48 devpinoyLogger Am at second line of log

Thanks
Happy logging