I tried the catalina.base variable but as far as i can see it puts it in Tomcat home dir not the webapp dir!

On 2010/04/29 12:34 PM, Pid wrote:
On 29/04/2010 11:27, Jamie wrote:
Hi There

We use multiple web applications running inside Tomcat and need a
painless way for each app to write to its own log file.

In our scenario, each web application has its own log4j.xml file and the
corresponding log file for each instance is stored in a unique location
for that application, namely:

WEBAPP/WEB-INF/logs
You're writing logs *inside* the webapp?  Yikes!


(so that each web application has its own log information)

Our log4j.xml file has an appender that looks as follows:

<appender name="debugAppender"
class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${ROOT}/WEB-INF/logs/debug.log"/>
There are other variables you can use, e.g.

  <param name="File" value="${catalina.base}/logs/debug.log"/>

${catalina.home} will also work.


p

<param name="MaxFileSize" value="100MB"/>
<param name="MaxBackupIndex" value="1"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%5p %d{MMM/dd HH:mm:ss} - %m%n"/>
</layout>
</appender>

You'll notice above, we refer to the system property {$ROOT} in the
log4j.xml file. This Java system variable
is set when the web application is first initialized.  The variable
during startup as follows:

public class AppServletContext implements ServletContextListener{
     ServletContext context;

     public void contextInitialized(ServletContextEvent event) {
         ServletContext context = event.getServletContext();
         String path = context.getRealPath(File.separator);
         if (path.endsWith(File.separator))
             path = path.substring(0,path.length()-1);
         int i = path.lastIndexOf(File.separator);
         String name = path.substring(i+1,path.length());
         System.setProperty(name,path);
     }

     public void contextDestroyed(ServletContextEvent event ) {
     }
}

The effect of the above is to set a Java System Property with the name
of the instance (e.g. ROOT) and value of the context path on startup. In
this way, we are able to refer to the context path, from within the
log4j.xml file. Thus, if the name of the web application being loaded is
appname... then the Java system system variable APPNAME will be set, and
we would create a log4j.xml with the variable ${APPNAME} to refer to the
application path.

While this approach does work, it requires  us to update the log4j.xml
for each instance. We need to change ${ROOT} to ${webappname}. This is a
pain when there are alot of web applications and each of their log4j.xml
files need to be updated. Are there any other ideas on how to  refer to
the current Tomcat web application  path from with the log4j.xml without
having to customize a log4j.xml file for each web application. I need a
simpler more generic way, such as
<param name="File" value="./WEB-INF/logs/debug.log"/>. Perhaps, there is
a simpler way that I missed.

Thanks in advance for your consideration

Jamie



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




--
Stimulus Software - MailArchiva
Email Discovery, Archiving And Compliance
USA Tel: +1-713-343-8824 ext 100
UK Tel: +44-20-80991035 ext 100
FAX: +1-(877)-350-2328
Email: ja...@stimulussoft.com <mailto:ja...@stimulussoft.com>
Web: www.mailarchiva.com <http://www.mailarchiva.com>

Click here <http://stimulussoft.eu/lists/?p=subscribe> to receive MailArchiva product announcements.

Reply via email to