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 Alex Colic <ac...@yahoo.com> on 2001/01/01 19:01:16 UTC
How to create different layout/appender configuration for different classes
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.
Hope the above makes sense.
Thanks for the help.
Alex
=====
Regards
Alex Colic, HBA, B. Ed
PopWare Inc. "Driving down the cost of conversions"
E-Mail: Alex.Colic@pop-ware.com
Tel: 1-905-777-8171 ext. 104
Fax: 1-905-777-0132
__________________________________________________
Do You Yahoo!?
Yahoo! Photos - Share your holiday photos online!
http://photos.yahoo.com/
Re: How to create different layout/appender configuration for
different classes
Posted by Ceki Gulcu <cg...@urbanet.ch>.
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