I was doing something like this with LogBack (successor to log4j more or less), 
but I'm no longer using it and don't remember how I set it up.  The class 
starts as follows:

 public final class InitLogback extends HttpServlet {
   @Override
   public void init() {
       final String pathPrefix = getServletContext().getRealPath("/");

And I think pathPrefix then contains the name of the directory in the tomcat 
webapps folder.

I don't remember how I was configuring this servlet in the web.xml file; 
possibly as a regular servlet with a load-on-startup value that was lower than 
the main (Spring) servlet.

I don't claim that this is the best way to accomplish this.

If you're using Spring you may want to look at its

org.springframework.web.util.Log4jWebConfigurer

and

org.springframework.web.util.Log4jConfigListener


Ken Bowen wrote:
All,

Apologies if I've missed the answer to this in the Logging HowTo, the FAQ, or Andre's collection of the logging discussion.

Env:  TC 6.0.18 + Java 1.5

The issue: I want to have several instances of the same webapp running on the same Tomcat as myapp1, myapp2, etc.
That's easy.

I'm going to be using log4j, probably with properties files, but xml would be ok too. I'd like to have log files named mylog.log appear in ${catalina.home}/logs looking like

    myapp1-mylog.log    myapp2-mylog.log    ... etc.

I could hardwire this in separte log4j.properties files for each myapp instance, something like this:

log4j.appender.myLogFile.File=${catalina.home}/logs/myapp1-mylog.log
log4j.appender.myLogFile.File=${catalina.home}/logs/myapp2-mylog.log

And using ant to build my war files, I could hide this ugliness, just copying such hardwired files into the war being built. But is there any parameter syntax that would allow me to grab the context name and write one log4j.properties with something like this:

log4j.appender.myLogFile.File=${catalina.home}/logs/${context-name}-mylog.log ??

Thanks,
Ken


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to