You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Gurkan Erdogdu <gu...@yahoo.com> on 2010/06/18 19:48:39 UTC

Re: how can i configure Tomcat's log4j to log in a separate file for each webapp?

Hello dB;

This is the step by step actions to configure your log4j logging in one place in Tomcat "lib/log4j.properties"

Actions
---------------------

1- Remove logging.properties from conf/logging.properties
2- Remove tomcat-juli.jar from bin/tomcat-juli.jar
3- Get "tomcat-juli.jar" and "tomcat-juli-adapters.jar" from "http://godel.cs.bilgi.edu.tr/apache/tomcat/tomcat-6/v6.0.26/bin/extras/" or any other place
4- Put "tomcat-juli.jar" to "bin" folder
5- Put "tomcat-juli-adapters.jar" to "lib" folder
6- Download "log4j.jar" and put to "lib" folder
7- Creates a log4j.properties and put it into "lib" folder.
Example Configuration:

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

//Manager application
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager]= DEBUG,B
log4j.appender.B=org.apache.log4j.RollingFileAppender 
log4j.appender.B.File=${catalina.base}/logs/gurkan.log  --> Its own log file
log4j.appender.B.MaxFileSize=10MB 
log4j.appender.B.MaxBackupIndex=10 
log4j.appender.B.layout=org.apache.log4j.PatternLayout 
log4j.appender.B.layout.ConversionPattern=%p %t %c - %m%n


//Example application
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/examples]= DEBUG,C
log4j.appender.C=org.apache.log4j.RollingFileAppender 
log4j.appender.C.File=${catalina.base}/logs/example.log  --> Its own 
log file
log4j.appender.C.MaxFileSize=10MB 
log4j.appender.C.MaxBackupIndex=10 
log4j.appender.C.layout=org.apache.log4j.PatternLayout 
log4j.appender.C.layout.ConversionPattern=%p %t %c - %m%n



This will creates a root logger --> INFO and logs message to tomcat.log.
Each web application can override ROOT like I did for manager and examples web applications.

I hope it helps :)))

--Gurkan





________________________________
From: dB. <db...@dblock.org>
To: Tomcat Users List <us...@tomcat.apache.org>
Sent: Fri, June 18, 2010 3:49:03 PM
Subject: RE: how can i configure Tomcat's log4j to log in a separate file for  each webapp?

That's exactly what I am trying to avoid :)

I have a lot of web apps and developers that stand on their head for logging. My customers end up finding logs all over the place and enforcing it by convention is getting harder and harder. I'd like to configure logging for them rather than leave logging to their discretion. So I want the centralized log4j configuration that can insert the web app name into the file name that belongs to the tomcat installation.

dB. @ dblock.org 
Moscow|Geneva|Seattle|New York



-----Original Message-----
From: Erik Bertelsen [mailto:bertelsen.erik@gmail.com] 
Sent: Friday, June 18, 2010 8:37 AM
To: Tomcat Users List
Subject: Re: how can i configure Tomcat's log4j to log in a separate file for each webapp?

2010/6/18 dB. <db...@dblock.org>:
> This question is all over the internet, without a satisfactory answer.
>
> We have a Tomcat deployment in which we install many web apps. We call this thing a services host. It has a log4j configuration that forwards logs into a file. I'd like to change the file pattern to include the name of the webapp, so that we can get one file per web application.
>
>
> *         Is anyone doing that?

I do this all the time.

For applications using commons-logging, I place commons-logging.jar
and log4j.jar in the webapp's WEB-INF/lib directory and
log4j.properties in WEB-INF/classes. The same works if slf4j-api and
slf4j-log4j12 is used instead of or in addition to commons-logging.

I never add jar files used by individual webapps to tomcat's lib or
any other directory shared by several webapps.

kind regards
- Erik

---------------------------------------------------------------------
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: how can i configure Tomcat's log4j to log in a separate file for each webapp?

Posted by "dB." <db...@dblock.org>.
And can I do this for an application I don't know anything about? I mean all I really want is 

log4j.appender.R.File=${catalina.base}/logs/${APPLICATION.NAME}.log


dB. @ dblock.org 
Moscow|Geneva|Seattle|New York



-----Original Message-----
From: Gurkan Erdogdu [mailto:gurkanerdogdu@yahoo.com] 
Sent: Friday, June 18, 2010 1:49 PM
To: Tomcat Users List
Subject: Re: how can i configure Tomcat's log4j to log in a separate file for each webapp?

Hello dB;

This is the step by step actions to configure your log4j logging in one place in Tomcat "lib/log4j.properties"

Actions
---------------------

1- Remove logging.properties from conf/logging.properties
2- Remove tomcat-juli.jar from bin/tomcat-juli.jar
3- Get "tomcat-juli.jar" and "tomcat-juli-adapters.jar" from "http://godel.cs.bilgi.edu.tr/apache/tomcat/tomcat-6/v6.0.26/bin/extras/" or any other place
4- Put "tomcat-juli.jar" to "bin" folder
5- Put "tomcat-juli-adapters.jar" to "lib" folder
6- Download "log4j.jar" and put to "lib" folder
7- Creates a log4j.properties and put it into "lib" folder.
Example Configuration:

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

//Manager application
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager]= DEBUG,B
log4j.appender.B=org.apache.log4j.RollingFileAppender 
log4j.appender.B.File=${catalina.base}/logs/gurkan.log  --> Its own log file
log4j.appender.B.MaxFileSize=10MB 
log4j.appender.B.MaxBackupIndex=10 
log4j.appender.B.layout=org.apache.log4j.PatternLayout 
log4j.appender.B.layout.ConversionPattern=%p %t %c - %m%n


//Example application
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/examples]= DEBUG,C
log4j.appender.C=org.apache.log4j.RollingFileAppender 
log4j.appender.C.File=${catalina.base}/logs/example.log  --> Its own 
log file
log4j.appender.C.MaxFileSize=10MB 
log4j.appender.C.MaxBackupIndex=10 
log4j.appender.C.layout=org.apache.log4j.PatternLayout 
log4j.appender.C.layout.ConversionPattern=%p %t %c - %m%n



This will creates a root logger --> INFO and logs message to tomcat.log.
Each web application can override ROOT like I did for manager and examples web applications.

I hope it helps :)))

--Gurkan





________________________________
From: dB. <db...@dblock.org>
To: Tomcat Users List <us...@tomcat.apache.org>
Sent: Fri, June 18, 2010 3:49:03 PM
Subject: RE: how can i configure Tomcat's log4j to log in a separate file for  each webapp?

That's exactly what I am trying to avoid :)

I have a lot of web apps and developers that stand on their head for logging. My customers end up finding logs all over the place and enforcing it by convention is getting harder and harder. I'd like to configure logging for them rather than leave logging to their discretion. So I want the centralized log4j configuration that can insert the web app name into the file name that belongs to the tomcat installation.

dB. @ dblock.org 
Moscow|Geneva|Seattle|New York



-----Original Message-----
From: Erik Bertelsen [mailto:bertelsen.erik@gmail.com] 
Sent: Friday, June 18, 2010 8:37 AM
To: Tomcat Users List
Subject: Re: how can i configure Tomcat's log4j to log in a separate file for each webapp?

2010/6/18 dB. <db...@dblock.org>:
> This question is all over the internet, without a satisfactory answer.
>
> We have a Tomcat deployment in which we install many web apps. We call this thing a services host. It has a log4j configuration that forwards logs into a file. I'd like to change the file pattern to include the name of the webapp, so that we can get one file per web application.
>
>
> *         Is anyone doing that?

I do this all the time.

For applications using commons-logging, I place commons-logging.jar
and log4j.jar in the webapp's WEB-INF/lib directory and
log4j.properties in WEB-INF/classes. The same works if slf4j-api and
slf4j-log4j12 is used instead of or in addition to commons-logging.

I never add jar files used by individual webapps to tomcat's lib or
any other directory shared by several webapps.

kind regards
- Erik

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