tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cpanon <>
Subject Re: deploy log4j
Date Thu, 09 Dec 2010 18:55:30 GMT
Hi Mark
Thank you for the extensive effort in response.  However it gets curiouser and 

Specifically when I deploy
JRE 6.0.22-b04 WEB-INF/classes/)
# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=WARN, A1

# A1 is set to be a ConsoleAppender.

# A1 uses PatternLayout.
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x %M - %m%n

on Win2KSrv, Win2003Srv, and WinXPP I get 
org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to 
which if "fixed" by this line in context.xml
<Loader delegate="true"/>  

This is the where the differences in the platforms affects the results with all 
of the above configs.
1.  On Windows2K Server and Windows2003 Server it fails to find the properly 
configured and located log4j file
2.  On WinXPP it works perfectly under production TC 6.0.29, finding the log4j 
file without error.

Any ideas?

From: Mark Eggers <>
To: Tomcat Users List <>
Sent: Thu, December 9, 2010 1:06:08 AM
Subject: Re: deploy log4j

You don't say the following:

Tomcat version
JRE/JDK version
Platform (OS and version)

That being said, I use log4j (with or without Apache commons logging) for nearly 

every web application I run on Tomcat.

Short answer: You don't manually read in your properties file with log4j.

Read a tutorial on log4j for a more complete explanation.

What follows below is an overview. Please refer to the log4j documentation, the 
log4j javadocs, and tutorials around the Internet for a more complete 


In each class that you want to use logging, add the following:

package foo; // replace with your package name

import org.apache.log4j.Logger;

public class MyFoo { // replace with your class name
    private static final Logger log = Logger.getLogger(MyFoo.class); // note 1

     * rest of class including log.xxxx("message") where xxxx is a level

note 1: While it is traditional that one uses getLogger(MyFoo.class), which is 
shorthand for getLogger(clazz.getName()), you can also name your loggers with 
any legal string. See the javadoc for more information.

Properties File:

In your properties file, you'll need appenders as well individual lines for 
non-default logging levels for each logger name.

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

# default logging level
log4j.rootLogger=warn, file

# logging for foo.MyFoo - name matches the logger name

Since there is only a file listed in the appenders, then that's where the 
logging will go.

Note that ${catalina.home} was used for logging. This should probably 
be ${catalina.base} just in case more than one copy of Tomcat is run from a base 

installation (see RUNNING.txt). This is a handy way of storing log files.

If you're doing some in-IDE testing where ${catalina.home} or ${catalina.base} 
is not set, then hopefully your IDE will let you pass in a Java parameter. Just 
-Dcatalina.home=<some-place> (or -Dcatalina.base=<some-place>) while testing.

Application Structure:

Properties file

Package up the application so that gets placed in
WEB-INF/classes/ Log4j looks for the properties file in the 
classpath. Placement in your IDE's project depends on how your IDE packages 

Log4j library

Package up the application so that log4j-1.2.15.jar (or whatever version you are 

using) gets placed in WEB-INF/lib/log4j-1.2.15.jar. Placement in your IDE's 
project depends on how your IDE packages files.

. . . . just my two cents.


----- Original Message ----
From: cpanon <>
To: Tomcat <>
Sent: Wed, December 8, 2010 8:23:46 PM
Subject: deploy log4j

I have an app that work perfectly in my IDE(JBuilder05, yes I know but it work 
fine), but on deployment I believe it is not reading the log4j with this error:
    at java.util.Properties$LineReader.readLine(Unknown Source)

followed by 
log4j:WARN No appenders could be found for logger 

I am loading the prop file with this(that works in the IDE)
java.util.Properties props = new java.util.Properties();
    try {
    catch (IOException ex) {


To unsubscribe, e-mail:
For additional commands, e-mail:
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message