Log4j with HTML output

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 with HTML output
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 log4jhtml.properties file as show : make sure this is under src folder 


# Define the root logger with file appender
log4j.rootLogger = DEBUG, HTML

# Define the file appender
log4j.appender.HTML=org.apache.log4j.FileAppender
log4j.appender.HTML.File=/youtprojectpath/src/com/log/application.html
# Define the html layout for file appender
log4j.appender.HTML.layout=org.apache.log4j.HTMLLayout
log4j.appender.HTML.layout.Title=Application logs
log4j.appender.HTML.layout.LocationInfo=true

log4j.appender.HTML.Threshold=DEBUG


Please see the snapshot for the same 




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



}



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




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





Thanks
Happy logging


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.