Category: JSP

How to integrate Log4J into a Java application

Its is best to log all messages to a individual log file instead of using the standard tomcat log files. Below is a quick tutorial to setup very simply logging using a JSP and a properties file. It is best to read the documentation available on the Log4J website to find out which is the best way to setup logging for your application.

  • Download Log4J from the web [
  • Place the log4j****.jar into your WEB-INF/lib directory. This is found in distlib in the downloaded archive file.
  • Create a property file as listed below named “”
# Log4j configuration file.
 log4j.rootCategory=DEBUG, A1
 # Available levels are DEBUG, INFO, WARN, ERROR, FATAL
 log4j.appender.A1.layout.ConversionPattern=%-5p %d{ISO8601} [%t - %m%n
  • Create simple JSP, ensure to import the correct packages
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import="org.apache.log4j.*" %>

<%="Hello World"%>
<% PropertyConfigurator.configure("");//This is best added to your startup page Logger logger = Logger.getRootLogger();"Hello World"); %>

0 0 vote
Article Rating

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.