Thanks for reminding me of the additivity flag. It doesn't solve the problem
100% but allowed me to come pretty close in a very easy way:
- Created MYCLASS appender that writes to MyClass.log.
- Created a <category> entry as follows:
<category name="mypackage.MyClass" additivity="false">
<priority value="DEBUG"/>
<appender-ref ref="MYCLASS"/>
</category>
This separated all of the output of MyClass to MyClass.log. What remains to be
done is to make MyClass' log entries of level INFO and higher return to the
main log.
I wish we could just define a second <category> entry for "mypackage.MyClass" -
with priority="INFO" and appender-ref pointing to the main appender. But log4j
isn't there yet.
bruno
-----Original Message-----
From: Brett Randall [mailto:[email protected]]
Sent: Sunday, January 17, 2010 3:36 AM
To: Log4J Users List
Subject: Re: Split logging by class/package
Bruno, have you tried setting the additivity flag for the MyClass logger to
"false"? Not sure if it meets all your needs, but it would allow you to
attach an appender to the MyClass logger and prevent propagation to ancestor
loggers and their appenders.
Brett
On Sat, Jan 16, 2010 at 3:37 AM, Bruno Melloni
<[email protected]>wrote:
> All examples on how to split logging across two appenders seem to be 'by
> level', and the XML configuration only has one set of <category> definitions
> rather than one set per appender. I need to split logging by both class and
> level:
>
>
> - Default log: Standard logging for the application, including
> log entries for 'MyClass' at INFO level and above.
>
> - MyClass log: Entries for MyClass only, at DEBUG level. It
> would be acceptable if it also contained MyClass higher logging levels.
>
> My need seems to be pretty standard. Is there a simple way to do this?
>
> The only solution I found (but not tried) seems too complicated to be
> right:
>
>
> - Setup the category for MyClass at DEBUG level.
>
> - Create a MyClass appender in log4j.xml.
>
> - Write a custom Filter that only accepts MyClass log entries of
> DEBUG level. Add the filter to the MyClass appender.
>
> - Write a custom Filter that accepts all log entries except
> MyClass DEBUG entries. Add the filter to the default appender.
>
> - Since I am using jBoss' logging facility, place these classes
> 'somewhere' that puts them in jBoss' classpath. Where would that be?
>
> Any guidance would be greatly appreciated.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]