[slf4j-user] Per-web-app logging with jars on the server's classpath

Mark Stralka mstralka at gmail.com
Fri Mar 16 12:37:58 CET 2007


Jacob Kjome <hoju <at> visi.com> writes:

> 
> 
> What are you doing to install the repository selector?  Are you doing it
> programatically or via the System property?  For instance, here's the System
> property to set in Weblogic's startup script...
> 
> -Dlog4j.repositorySelector=JNDI
> OR
> -Dlog4j.repositorySelector=com.mycompany.MyCustomSelector

I am doing it programatically in each webapp's StartupListener:
public void contextInitialized(ServletContextEvent event) {
...
  LogManager.setRepositorySelector(new ContextJNDISelector(), null);
...
}

I will also try using -Dlog4j.repositorySelector=JNDI

> 
> Oh, and I presume your "log4j_webapp.properties" is sitting in the default
> package in the classpath of the webapp, such as in the "WEB-INF/classes"
> directory, right?  Or, you can also have it on the System classpath if you 
want
> all apps to use the same config file.  It uses the context class loader, so 
it 
> should attempt to look it up first in the classloader from which the thread 
was
> initiated and fall back to the system classloader via standard classloader
> delegation.

Each web app looks like this:
WEB-INF/classes/log4j_webapp.properties

Each log4j_webapp.properties file looks like this (and 
com.myframework.xxx is from myframework.jar, which is on 
weblogic classpath)

log4j.rootLogger=warn, file

### direct messages to file <app name>.log ###
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.DatePattern='.'yyyy-MM-dd
log4j.appender.file.File=c:/logs/<webapp_name>.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy\
 HH:mm:ss,SSS} %5p
%C{1} - %m%n

log4j.logger.org.apache.struts=error
log4j.logger.org.apache.struts.taglib.tiles=fatal
log4j.logger.org.apache.commons=error
log4j.logger.org.apache.jcs=error
log4j.logger.org.springframework=error
log4j.logger.org.hibernate=error
log4j.logger.org.acegisecurity=error

#log messages from classes in myframework.jar on server's classpath
#each web app may want different levels of logging on 
#these classes, which is why we need separate log files 
#for each web app
log4j.logger.com.myframework=warn
log4j.logger.com.myframework.dao=warn
log4j.logger.com.myframework.service=debug
log4j.logger.com.myframework.web=debug

> 
> BTW, there's also a utility for removing logger repository for an app 
when it
> shuts down, though I'm not sure it's yet included in the latest 1.3alpha
jar
> available for download, but is in the SVN source [1].  We really need to 
create
> another alpha release to pick up changes over the last, well..., a little 
over a
> year.  For this reason, I actually suggest that you build Log4j-1.3 from 
source
> instead of using the existing downloadable binary.
> 
> [1]
>
http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/
selector/servlet/ContextDetachingSCL.java
> 
> Jake
> 

I am using 1.3alpha8 from source - what is the utility for removing logger
repository during shutdown?

Thanks again





More information about the slf4j-user mailing list