tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Eggers <>
Subject Re: Missing files for Apache and Log4J
Date Fri, 29 Jul 2011 18:04:51 GMT
> From: A Df <>

> Dear All:
> I have created a Java web application and I want to have logging to ensure that 
> the appropriate messages are stored in log files instead of to standard output. 
> I found a link at and was 
> following the instruction but I am unclear for these steps. My details are:
>     * Apache Tomcat 6.0.26
>     * Log 4j 1.2.16
> The instructions specify
>     * Build or download the additional logging components.
> I am new to logging, so I am not sure what other extra are needed!
>     * Replace $CATALINA_HOME/bin/tomcat-juli.jar with 
> output/extras/tomcat-juli.jar.
> Does this mean that I move the jar from that location and create the folders to 
> put it in another location to have :C:\Program Files\Apache Software 
> Foundation\Apache Tomcat 6.0.26\output\extras?
>     * Place output/extras/tomcat-juli-adapters.jar in $CATALINA_HOME/lib.I 
> cannot find the jar file in the Log4J download or Apache files so where is it 
> located?
> Is Log4J the best logging to use with a Java web app? Do you have any 
> suggestions?
> Thanks for your help,
> A Df

Logging for a particular web application is different (or can be) than
logging for Tomcat.

What I normally do is leave Tomcat logging as is (or modify it for
better cluster logging), and use logging-commons / log4j for web

Using logging-commons / log4j for a particular web application is
pretty straightforward.

1. Include commons-logging-1.1.1.jar and log4j-1.2.15.jar in your
   application's WEB-INF/lib folder

2. Create a file or a log4j.xml file and place it
   in the application's WEB-INF/class folder

3. Add logging instructions to your classes

By default logging-commons will use log4j, so no other special
configuration is necessary.

It's nice to use logging-commons, since this makes it easier to switch
out logging from log4j to another package should you choose to.

Since I know you use NetBeans, the following is NetBeans-specific:

* Add the jars

There are several ways to include third party jars in your
project. The quick and dirty way is to do the following.

1. Create a folder (call it libs) in your project
2. Copy the jars into that folder
3. Right-mouse click on the Libraries node in your project
4. Select Add Jar/Folder
5. Browse to where you copied the jar files
6. Add them

By default, those jars will now be packaged up in the WAR file and
included in your application's WEB-INF/lib folder.

For individual development this is probably OK. For a more robust
environment, it might be nice to add the jars to version control, create a
NetBeans library with the two jars, or even use Maven or Ivy to manage

* Create a properties file

I actually prefer using the xml file, but there are several open
issues with using custom DTDs or schemas when editing XML files with
NetBeans. So, a properties file is easier to use.

1. Navigate to your Source Packages -> <default package> node
2. Right-mouse click and select New -> Other
3. Find Properties File in the dialog box (it's under Other)
4. Call it log4j (NetBeans adds the .properties)
5. Edit away

NetBeans will package up the file in WEB-INF/classes of your
application, where it can be found by the log4j classes.

Here's a quick example of a file:

### direct messages to file simple.log ###
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### default logging level

### for the simple application

Read the documentation that comes with log4j on how to create files for more information. For example, change the
log4j.logger definitions to fit your package names and desired level
of logging.

One thing of interest to note here is where the log gets written. I've
used ${catalina.base}/logs as the directory for the log file. This
will write simple.log in the same logging directory that Tomcat
uses. This may or may not be what you want. Change the location as

. . . . just my two cents.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message