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 "Brzezicki, Jerzy" <Je...@railinc.com> on 2001/12/18 00:15:04 UTC

two separate categories and log files

Hi,

I am trying to define two seperate categories, so I can write to two
different files ("fileA" and "fileB").
I want to be able to do:

catA.debug("A");
and 
catB.debug("B");

and want "A" to be only in fileA and "B" only in fileB.

It looks like my appenders accumulate in root category and I am getting
messages in both files.
Is it possible to do this ?

Thanks,
Jerzy

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: two separate categories and log files

Posted by Thomas Tuft Muller <tt...@online.no>.
log4j.xml (excerpt)

	<!-- Root category -->
	<root>
		<Priority value="debug" />
		<appender-ref ref="MAIN" />
	</root>

	<category name="a">
		<Priority value="debug"/>
		<Additivity value="false"/>
		<appender-ref ref="A"/>
	</category>

	<category name="b">
		<Priority value="debug"/>
		<Additivity value="false"/>
		<appender-ref ref="B"/>
	</category>

	<appender name="MAIN" class="org.apache.log4j.FileAppender">
		<param name="File" value="main.log" />
		<layout class="org.apache.log4j.PatternLayout">
  			<param name="ConversionPattern"
  				value="%d{ISO8601} - &quot;%m&quot;%n" />
		</layout>
	</appender>

	<appender name="A" class="org.apache.log4j.FileAppender">
		<param name="File" value="fileA.log" />
		<layout class="org.apache.log4j.PatternLayout">
  			<param name="ConversionPattern"
  				value="%d{ISO8601} - &quot;%m&quot;%n" />
		</layout>
	</appender>

	<appender name="B" class="org.apache.log4j.FileAppender">
		<param name="File" value="fileB.log" />
		<layout class="org.apache.log4j.PatternLayout">
  			<param name="ConversionPattern"
  				value="%d{ISO8601} - &quot;%m&quot;%n" />
		</layout>
	</appender>

Code:

Category catA = Category.getInstance( "a" );
Category catB = Category.getInstance( "b" );

catA.debug( "I am a" );
catB.debug( "I am b" );

These two entries will end up in fileA.log and fileB.log respectively. Both
entries will be found in main.log.

Hope this helps.

--

Thomas

| -----Original Message-----
| From: Brzezicki, Jerzy [mailto:Jerzy.Brzezicki@railinc.com]
| Sent: 17 December 2001 23:15
| To: 'log4j-user@jakarta.apache.org'
| Subject: two separate categories and log files
|
|
| Hi,
|
| I am trying to define two seperate categories, so I can write to two
| different files ("fileA" and "fileB").
| I want to be able to do:
|
| catA.debug("A");
| and
| catB.debug("B");
|
| and want "A" to be only in fileA and "B" only in fileB.
|
| It looks like my appenders accumulate in root category and I am getting
| messages in both files.
| Is it possible to do this ?
|
| Thanks,
| Jerzy
|
| --
| To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>




*************************************************************************
Copyright ERA Technology Ltd. 2001. (www.era.co.uk). All rights reserved. 
Confidential. No liability whatsoever is accepted for any loss or damage 
suffered as a result of accessing this message or any attachments.

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>