You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jamie <ja...@stimulussoft.com> on 2010/04/29 12:27:37 UTC

logging in multiple tomcat web applications

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

(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"/>
<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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: logging in multiple tomcat web applications

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Jamie [mailto:jamie@stimulussoft.com]
> Subject: Re: logging in multiple tomcat web applications
> 
> I tried the catalina.base variable but as far as i can see it puts it
> in Tomcat home dir not the webapp dir!

As stated before, writing logs to a webapp's directory is *always* a really bad idea.  Put them in a reasonable location.

 - Chuck

 
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


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


Re: logging in multiple tomcat web applications

Posted by Jamie <ja...@stimulussoft.com>.
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-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@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: jamie@stimulussoft.com <ma...@stimulussoft.com>
Web: www.mailarchiva.com <http://www.mailarchiva.com>

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

Re: logging in multiple tomcat web applications

Posted by Pid <pi...@pidster.com>.
On 29/04/2010 11:45, Jamie wrote:
> 
> Aah.. Just what I was looking for.. Thanks! Is it bad to write logs
> inside WEB-INF?

Writing anything inside a deployed webapp isn't such a good idea.
If it's undeployed, then *paf* all your content is gone.

If the app got undeployed because of a problem (somehow, may be
unlikely, but hey) then you'd lose the log files and any ability to work
out what happened.


p

> Jamie
> 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!
>>
>>
>>    
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 



RE: logging in multiple tomcat web applications

Posted by Karthik Nanjangude <ka...@xius-bcgi.com>.
Hi

My suggestion would be to point the logger (log4j.xml) to place the logs in

"Tomcat / logs / abclog / folder"

This would be safe and not be visible or it is readable by the world



With regards
karthik


-----Original Message-----
From: Jamie [mailto:jamie@stimulussoft.com]
Sent: Thursday, April 29, 2010 5:20 PM
To: Tomcat Users List
Subject: Re: logging in multiple tomcat web applications

If we do that, then it will be sitting in the webapp directory where if
permissions are not set correctly, it is readable by the world.

On 2010/04/29 01:47 PM, David kerber wrote:
> Just move the log folder up a level.
>
>
> On 4/29/2010 7:04 AM, Jamie wrote:
>> Ok. We are not using Tomcat's web app deploy feature at all. We manage
>> the deployment of instances. Where then should all the configuration and
>> log data go? I presume with Windows 7, they have protections storing the
>> data in the Program Files directory in any case. Should they go in


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


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


Re: logging in multiple tomcat web applications

Posted by Jamie <ja...@stimulussoft.com>.
If we do that, then it will be sitting in the webapp directory where if 
permissions are not set correctly, it is readable by the world.

On 2010/04/29 01:47 PM, David kerber wrote:
> Just move the log folder up a level.
>
>
> On 4/29/2010 7:04 AM, Jamie wrote:
>> Ok. We are not using Tomcat's web app deploy feature at all. We manage
>> the deployment of instances. Where then should all the configuration and
>> log data go? I presume with Windows 7, they have protections storing the
>> data in the Program Files directory in any case. Should they go in


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


Re: logging in multiple tomcat web applications

Posted by David kerber <dc...@verizon.net>.
Just move the log folder up a level.


On 4/29/2010 7:04 AM, Jamie wrote:
> Ok. We are not using Tomcat's web app deploy feature at all. We manage
> the deployment of instances. Where then should all the configuration and
> log data go? I presume with Windows 7, they have protections storing the
> data in the Program Files directory in any case. Should they go in
> user.home?
>
> On 2010/04/29 12:57 PM, Mark Thomas wrote:
>> On 29/04/2010 05:45, Jamie wrote:
>>>
>>> Aah.. Just what I was looking for.. Thanks! Is it bad to write logs
>>> inside WEB-INF?
>>
>> Generally, yes. When the application gets (un|re)deployed, the logs
>> will get deleted. That isn't usually what you want.
>>
>> Mark
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>
>


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


Re: logging in multiple tomcat web applications

Posted by Jamie <ja...@stimulussoft.com>.
Ok. We are not using Tomcat's web app deploy feature at all. We manage 
the deployment of instances. Where then should all the configuration and 
log data go? I presume with Windows 7, they have protections storing the 
data in the Program Files directory in any case. Should they go in 
user.home?

On 2010/04/29 12:57 PM, Mark Thomas wrote:
> On 29/04/2010 05:45, Jamie wrote:
>>
>> Aah.. Just what I was looking for.. Thanks! Is it bad to write logs
>> inside WEB-INF?
>
> Generally, yes. When the application gets (un|re)deployed, the logs 
> will get deleted. That isn't usually what you want.
>
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@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: jamie@stimulussoft.com <ma...@stimulussoft.com>
Web: www.mailarchiva.com <http://www.mailarchiva.com>

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

Re: logging in multiple tomcat web applications

Posted by Mark Thomas <ma...@apache.org>.
On 29/04/2010 05:45, Jamie wrote:
>
> Aah.. Just what I was looking for.. Thanks! Is it bad to write logs
> inside WEB-INF?

Generally, yes. When the application gets (un|re)deployed, the logs will 
get deleted. That isn't usually what you want.

Mark

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


Re: logging in multiple tomcat web applications

Posted by Jamie <ja...@stimulussoft.com>.
Aah.. Just what I was looking for.. Thanks! Is it bad to write logs 
inside WEB-INF?

Jamie
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!
>
>
>    



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


Re: logging in multiple tomcat web applications

Posted by Pid <pi...@pidster.com>.
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-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>