logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ceki Gulcu <...@urbanet.ch>
Subject Re: How to create different layout/appender configuration for different classes
Date Mon, 01 Jan 2001 19:55:10 GMT
At 10:01 01.01.2001 -0800, Alex Colic wrote:
>Hi,
>
>I am trying to get a handle on creating different appender/layout 
>configuration settings for
>different classes. Lets say I have a main class that instantiates a couple 
>of other classes called
>cirlce and square. I am using the following property file for the main 
>class and for the circle
>and square class. I am doing this so that my project will have one 
>configuration file common to
>all classes. The configuration file is as follows:
>
>log4j.rootCategory=debug, stdout, R
>
>log4j.appender.stdout=org.log4j.FileAppender
>log4j.appender.stdout.File=System.out
>log4j.appender.stdout.layout=org.log4j.PatternLayout
>
># Pattern to output the caller's file name and line number.
>log4j.appender.stdout.layout.ConversionPattern=%5p [%t] 
>(%F:%L)-(%M)-(%d{ISO8601}) - %m%n
>
>log4j.appender.R=org.log4j.RollingFileAppender
>log4j.appender.R.File=Log4JExample.log
>
>log4j.appender.R.MaxFileSize=100KB
># Keep one backup file
>log4j.appender.R.MaxBackupIndex=1
>
>log4j.appender.R.layout=org.log4j.PatternLayout
>log4j.appender.R.layout.ConversionPattern=%p %d{ISO8601} %t %c - %m%n
>
>log4j.category.circle=WARN
>log4j.category.square=ERROR
>
>My problem is that the way I have structured this file I only have the 
>default rootCategory. How
>do I sturucture this file so that there are seperate appender/layout 
>configurations for the circle
>and square classes. In each of these classes I use
>
>static Category cat = Category.getInstance(circle.class.getName());
>
>to instantiate the log settings.

Alex,

You can attach appenders to any category. How about:

log4j.category.circle=WARN, C
log4j.appender.C=org.log4j.FileAppender
log4j.appender.C.File=circle.out
log4j.appender.C.layout=org.log4j.PatternLayout
log4j.appender.C.layout.ConversionPattern=%p - %m%n
....

Similarly, you can attach an appender or appenders to the square category. 
Does that answer the question? Ceki


Mime
View raw message