Procedure: Using Log4j in Eclipse

1 About this document

This document outlines a few unofficial steps on implementing log4j in Eclipse. In this case we are on a Unix based OS.
Java developers using Eclipse
Eclipse IDE
This version date
02/20/09 12:45:16 PM

2 Downloading the software

  1. Download log4j tar.gz from the following URL

3 Unpacking and setting it up

  1. Change to your $JAVA_HOME directory and unpack the .tar.gz

    cd $JAVA_HOME
    tar -zxvf apache-log4j-1.2.15.tar.gz
  2. Go into the apache-log4j-1.2.15 directory and copy the log4j Jar file to the WEB-INF/lib directory in your project.

  3. Right click on your src folder and create a new file called ( this is the default place that log4j looks for its properties file ) if you are using J2EE view in Eclipse you won’t see the src folder, change to the plain Java view instead for a while.

  4. graphics1

  5. Paste the following code into the file that you just created

log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE}%5p%6.6r[%t]%x - %C.%M(%F:%L) - %m%n
log4j.rootLogger=debug, stdout

4 Java Code using Servlets

  1. Insert this code in the .java file that you wish to log (where servlet is the name of the servlet where you are placing this code)

    static Logger log = Logger.getLogger("");
  2. When you want to log enter any the following






5 Java Code using JSP

<%org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("index.jsp");%>  
<%"This is a log"); %>

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s