tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Kjome <h...@visi.com>
Subject Re: How to approximate tomcat-5.0/4.x/3.x logging in 5.5?
Date Wed, 02 Mar 2005 05:25:20 GMT

You first talk about ServletContext.log(), but then talk about log4j 
loggers in your app.  These are two completely separate things.  Which were 
you focusing on?  With your setup, it it makes sense that 
ServletContext.log() messages are going to catalina.log.  However, if you 
have log4j.jar in WEB-INF/lib and your application log4j logging is going 
to catalina.log, then your setup is different than what you describe 
here.  There is quite simply no way that can happen given the setup you've 
described.  They should go to "bar.log" since that's the only appender that 
your application's log4j configuration can see.  In any case, you don't 
need a separate log4j.jar in WEB-INF/lib for ServletContext.log() messages 
to go to app-specific log files.  Just define those in your 
log4j.properties just like you have defined the host logger.  Here's my 
setup for Log4j-1.2.9 in common/classes.log4j.properties (You can use 
log4j.xml when using Log4j-1.3 because it uses a the new JoranConfigurator 
which doesn't define a log4j.dtd.  The current DOMConfigurator's dtd 
defines the <logger> "name" attribute as an ID and the host and context 
logger names that Tomcat uses characters not allowed in attributes of type 
"id")....

log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-5p[%-8.8t]: %39.39c %-6r - %m%n

log4j.appender.LOCALHOST=org.apache.log4j.RollingFileAppender
log4j.appender.LOCALHOST.File=${catalina.home}/logs/localhost.log
log4j.appender.LOCALHOST.MaxFileSize=1000KB
log4j.appender.LOCALHOST.MaxBackupIndex=1
log4j.appender.LOCALHOST.layout=org.apache.log4j.PatternLayout
log4j.appender.LOCALHOST.layout.ConversionPattern=%-5p[%-8.8t]: %39.39c 
%-6r - %m%n

log4j.appender.MYAPP=org.apache.log4j.DailyRollingFileAppender
log4j.appender.MYAPP.File=${catalina.base}/logs/localhost_myapp.log
log4j.appender.MYAPP.DatePattern='.'yyyy-MM-dd
log4j.appender.MYAPP.layout=org.apache.log4j.PatternLayout
log4j.appender.MYAPP.layout.ConversionPattern=%c{1} %-6r - %m%n

log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/myapp]=INFO,

MYAPP
log4j.additivity.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/myapp]=false

log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=INFO, 
LOCALHOST
log4j.additivity.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=false

log4j.rootLogger=INFO, A1


Note that I use a ConsoleAppender because when I run from the command line, 
I want the output going to the command window.  When I use a service, the 
service captures the console output and writes it to a log file named 
"stdout.log".  This is why I don't specify the file.  It is done for me 
(and rolled daily for me).  Also note the use of additivity on the host and 
context loggers.  This is to avoid double logging to the appender 
configured by the root logger and the one specifically configured for the 
host/context log.

BTW, you don't need commons-logging in your webapp.  It is only Tomcat that 
needs it, so just put it in common/lib, not WEB-INF/lib.  You can continue 
to put log4j.jar in both places if you desire.  Otherwise, you can also use 
a repository selector to separate webapp logging with a single log4j.jar in 
common/lib.  This makes more sense to start doing with Log4j-1.3, though, 
using the ContextJNDISelector.  You get the same effect by having log4j.jar 
in WEB-INF/lib since the classloader isolation will, effectively, create 
logging isolation per webapp.


Jake

At 06:18 PM 3/1/2005 -0500, you wrote:
 >I'm having trouble approximating the earlier tomcat per-context
 ><Logger> functionality using log4j under tomcat-5.5.  Basically, I
 >would like to have one file coming out under $CATALINA_BASE/logs/ per
 >web application context.  This appears to be no longer possible through
 >ServletContext.log().  So I tried using log4j:
 >
 >1) put log4j.jar, commons-logging.jar in common/lib AND
 >webapps/*/WEB-INF/lib
 >2) put log4j.properties in common/classes AND webapps/*/WEB-INF/classes
 >
 >However, I can't seem to find the right combination of log4j.properties
 >lines, or maybe I'm trying something impossible.  (I can't find good
 >docs on the uses of log4j.properties when used inside the hierarchical
 >classloading context that tomcat provides.)  What keeps happening is
 >that the webapp's log statements keep going into the global tomcat log.
 >  Would I be better off with JDK logging instead?
 >
 >common/classes/log4j.properties
 >-------------------
 >log4j.rootLogger               info, R
 >log4j.appender.R               org.apache.log4j.RollingFileAppender
 >log4j.appender.R.File          ${catalina.base}/logs/tomcat.log
 >log4j.appender.R.MaxFileSize   10MB
 >log4j.appender.R.MaxBackupIndex        10
 >log4j.appender.R.layout                org.apache.log4j.PatternLayout
 >
 >log4j.appender.R.layout.ConversionPattern      %p %t %c - %m%n
 >
 >#log4j.logger.org.apache.catalina                      info, R
 >#log4j.logger.org.apache.catalina.session              info, R
 >#log4j.logger.org.apache.catalina.session.ManagerBase  info, R
 >
 >log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhos
 >t]=info, R
 >-------------------
 >
 >webapp/*/classes/log4j.properties
 >-------------------
 ># is this necessary?  tried with and without...
 >log4j.rootLogger               info, A1
 >
 >log4j.category.com.foo , A1
 >log4j.appender.A1              org.apache.log4j.DailyRollingFileAppender
 >log4j.appender.A1.File         ${catalina.base}/logs/bar.log
 >log4j.appender.A1.MaxFileSize  10MB
 >
 >log4j.appender.A1.MaxBackupIndex       10
 >log4j.appender.A1.layout               org.apache.log4j.PatternLayout
 >log4j.appender.A1.Append       true
 >
 >log4j.appender.A1.layout.ConversionPattern     %p %t %c - %m%n
 >
 >log4j.logger.com.foo   info, A1
 >-------------------
 >
 >Code in webapp:
 >-------------------
 >Logger logger = Logger.getLogger("com.foo");
 >logger.info("bar");
 >-------------------
 >
 >Any help appreciated..
 >
 >
 >---------------------------------------------------------------------
 >To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
 >For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
 >
 >  


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message