You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Sebastian Redl <wa...@gmx.net> on 2006/11/10 14:32:00 UTC

Sharing appender parameters

Hi,

I've got Tomcat 5.5 set up to use Log4j for logging. (I'm more
comfortable with that than JULI.)

In short, I want one log file per vhost. My current system is rather
crude, I think: have one RollingFileAppender per vhost, and the logger
for that vhost referring to this appender:

log4j.rootLogger=WARN, 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
log4j.logger.org.apache.catalina=INFO, R

log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=INFO,
localhost
log4j.appender.localhost=org.apache.log4j.RollingFileAppender
log4j.appender.localhost.File=${catalina.base}/logs/localhost.log
log4j.appender.localhost.MaxFileSize=10MB
log4j.appender.localhost.MaxBackupIndex=10
log4j.appender.localhost.layout=org.apache.log4j.PatternLayout
log4j.appender.localhost.layout.ConversionPattern=%p %t %c - %m%n

log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[www.tuxcat.local]=INFO,
tuxcat
log4j.appender.tuxcat=org.apache.log4j.RollingFileAppender
log4j.appender.tuxcat.File=${catalina.base}/logs/tuxcat.log
log4j.appender.tuxcat.MaxFileSize=10MB
log4j.appender.tuxcat.MaxBackupIndex=10
log4j.appender.tuxcat.layout=org.apache.log4j.PatternLayout
log4j.appender.tuxcat.layout.ConversionPattern=%p %t %c - %m%n

log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[www.sciencemapper.local]=INFO,
sciencemapper
log4j.appender.sciencemapper=org.apache.log4j.RollingFileAppender
log4j.appender.sciencemapper.File=${catalina.base}/logs/sciencemapper.log
log4j.appender.sciencemapper.MaxFileSize=10MB
log4j.appender.sciencemapper.MaxBackupIndex=10
log4j.appender.sciencemapper.layout=org.apache.log4j.PatternLayout
log4j.appender.sciencemapper.layout.ConversionPattern=%p %t %c - %m%n


As you can see, most of this stuff is constantly duplicated: the
appender class, max file size and backup index, and the layout. The only
thing that changes between appenders is the file name.

Is there a way to make this simpler? Either by having a single appender
that switches file name depending on the logger that calls it (unlikely
that this is possible) or by having appender defaults/prototypes so I
don't have to repeat the configuration all the time?

If that's not possible in 1.2, will it be in 1.3's XML configuration?
(Can't use 1.2's XML configuration with Tomcat's vhost loggers.) Would
it be too late for a feature request?

Sebastian Redl


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Sharing appender parameters

Posted by James Stauffer <st...@gmail.com>.
My DateFormatFileAppender potentially changes filename every time it
is called.  You could look into doing something similar.
http://stauffer.james.googlepages.com/DateFormatFileAppender.java

On 11/10/06, Sebastian Redl <wa...@gmx.net> wrote:
> Hi,
>
> I've got Tomcat 5.5 set up to use Log4j for logging. (I'm more
> comfortable with that than JULI.)
>
> In short, I want one log file per vhost. My current system is rather
> crude, I think: have one RollingFileAppender per vhost, and the logger
> for that vhost referring to this appender:
>
> log4j.rootLogger=WARN, 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
> log4j.logger.org.apache.catalina=INFO, R
>
> log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=INFO,
> localhost
> log4j.appender.localhost=org.apache.log4j.RollingFileAppender
> log4j.appender.localhost.File=${catalina.base}/logs/localhost.log
> log4j.appender.localhost.MaxFileSize=10MB
> log4j.appender.localhost.MaxBackupIndex=10
> log4j.appender.localhost.layout=org.apache.log4j.PatternLayout
> log4j.appender.localhost.layout.ConversionPattern=%p %t %c - %m%n
>
> log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[www.tuxcat.local]=INFO,
> tuxcat
> log4j.appender.tuxcat=org.apache.log4j.RollingFileAppender
> log4j.appender.tuxcat.File=${catalina.base}/logs/tuxcat.log
> log4j.appender.tuxcat.MaxFileSize=10MB
> log4j.appender.tuxcat.MaxBackupIndex=10
> log4j.appender.tuxcat.layout=org.apache.log4j.PatternLayout
> log4j.appender.tuxcat.layout.ConversionPattern=%p %t %c - %m%n
>
> log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[www.sciencemapper.local]=INFO,
> sciencemapper
> log4j.appender.sciencemapper=org.apache.log4j.RollingFileAppender
> log4j.appender.sciencemapper.File=${catalina.base}/logs/sciencemapper.log
> log4j.appender.sciencemapper.MaxFileSize=10MB
> log4j.appender.sciencemapper.MaxBackupIndex=10
> log4j.appender.sciencemapper.layout=org.apache.log4j.PatternLayout
> log4j.appender.sciencemapper.layout.ConversionPattern=%p %t %c - %m%n
>
>
> As you can see, most of this stuff is constantly duplicated: the
> appender class, max file size and backup index, and the layout. The only
> thing that changes between appenders is the file name.
>
> Is there a way to make this simpler? Either by having a single appender
> that switches file name depending on the logger that calls it (unlikely
> that this is possible) or by having appender defaults/prototypes so I
> don't have to repeat the configuration all the time?
>
> If that's not possible in 1.2, will it be in 1.3's XML configuration?
> (Can't use 1.2's XML configuration with Tomcat's vhost loggers.) Would
> it be too late for a feature request?
>
> Sebastian Redl
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Sharing appender parameters

Posted by Jacob Kjome <ho...@visi.com>.
It should work to define the common stuff as properties and reference 
them further down the file.  So...

appenderClass=org.apache.log4j.RollingFileAppender

...
...

log4j.appender.tuxcat=${appenderClass}

Just apply the same thing to all the other common stuff.  I haven't 
tried this, so I can't guarantee it will work.  I think Log4j only 
looks for properties starting with "log4j.", so Log4j should ignore 
declarations the other properties.  And I'm pretty sure that you can 
refer to a local property in the same property file using the 
${propname} syntax.

I'm not sure what equivalent would be for XML.  You couldn't do this 
other than using system properties with Log4j-1.2.xx.  I'm not sure 
about 1.3.  You might be able to write Joran rules to store the 
properties and use their values later in the file.  Not sure?

Jake


At 07:32 AM 11/10/2006, you wrote:
 >Hi,
 >
 >I've got Tomcat 5.5 set up to use Log4j for logging. (I'm more
 >comfortable with that than JULI.)
 >
 >In short, I want one log file per vhost. My current system is rather
 >crude, I think: have one RollingFileAppender per vhost, and the logger
 >for that vhost referring to this appender:
 >
 >log4j.rootLogger=WARN, 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
 >log4j.logger.org.apache.catalina=INFO, R
 >
 >log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localh
 >ost]=INFO,
 >localhost
 >log4j.appender.localhost=org.apache.log4j.RollingFileAppender
 >log4j.appender.localhost.File=${catalina.base}/logs/localhost.log
 >log4j.appender.localhost.MaxFileSize=10MB
 >log4j.appender.localhost.MaxBackupIndex=10
 >log4j.appender.localhost.layout=org.apache.log4j.PatternLayout
 >log4j.appender.localhost.layout.ConversionPattern=%p %t %c - %m%n
 >
 >log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[www.tu
 >xcat.local]=INFO,
 >tuxcat
 >log4j.appender.tuxcat=org.apache.log4j.RollingFileAppender
 >log4j.appender.tuxcat.File=${catalina.base}/logs/tuxcat.log
 >log4j.appender.tuxcat.MaxFileSize=10MB
 >log4j.appender.tuxcat.MaxBackupIndex=10
 >log4j.appender.tuxcat.layout=org.apache.log4j.PatternLayout
 >log4j.appender.tuxcat.layout.ConversionPattern=%p %t %c - %m%n
 >
 >log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[www.sc
 >iencemapper.local]=INFO,
 >sciencemapper
 >log4j.appender.sciencemapper=org.apache.log4j.RollingFileAppender
 >log4j.appender.sciencemapper.File=${catalina.base}/logs/sciencemapper.log
 >log4j.appender.sciencemapper.MaxFileSize=10MB
 >log4j.appender.sciencemapper.MaxBackupIndex=10
 >log4j.appender.sciencemapper.layout=org.apache.log4j.PatternLayout
 >log4j.appender.sciencemapper.layout.ConversionPattern=%p %t %c - %m%n
 >
 >
 >As you can see, most of this stuff is constantly duplicated: the
 >appender class, max file size and backup index, and the layout. The only
 >thing that changes between appenders is the file name.
 >
 >Is there a way to make this simpler? Either by having a single appender
 >that switches file name depending on the logger that calls it (unlikely
 >that this is possible) or by having appender defaults/prototypes so I
 >don't have to repeat the configuration all the time?
 >
 >If that's not possible in 1.2, will it be in 1.3's XML configuration?
 >(Can't use 1.2's XML configuration with Tomcat's vhost loggers.) Would
 >it be too late for a feature request?
 >
 >Sebastian Redl
 >
 >
 >---------------------------------------------------------------------
 >To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
 >For additional commands, e-mail: log4j-user-help@logging.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org