On Aug 23, 2007, at 3:24 PM, Ashish Kulkarni wrote:

Hi
I am using XML to define my logging properties,
I wanted to know if i can define 2 log files, and have logs in them
depending on which class is writing log file
for example

if the package is
com.test.me then the logs should be written to mylog.xml file

if the class is
com.test.me.my.Test then the logs should be written to mytest.log file.

Here is my XML file



+ <log4j:configuration threshold="debug">

<appender name="A1" class="org.apache.log4j.DailyRollingFileAppender" >
<param name="File" value="C:\\mylog.xml" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />

<layout class="org.apache.log4j.xml.XMLLayout">
</layout>
</appender>

<appender name="A2" class="org.apache.log4j.DailyRollingFileAppender" >
<param name="File" value="c:\\ mytest.log" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) - %m%n" />
</layout>
</appender>


Replace this section:

<category name="com.test.me">
<priority value="debug" />

<appender-ref ref="A1" />
</category>


<category name="com.test.me.my.Test">
<priority value="debug" />

<appender-ref ref="A2" />
</category>


<root>

<appender-ref ref="A1" />
<appender-ref ref="A2" />

</root>

with:

<!-- all requests from com.test.me.my.Test or descendents go to A2 and do not propagate to root -->
<logger name="com.test.me.my.Test" additivity="false">
    <appender-ref ref="A2"/>
</logger>

<!--  any requests except those from com.test.me go to A1  -->
<root>
   <level value="debug"/>
   <appender-ref ref="A1"/>
</root>

</log4j:configuration>


Your configuration would have routed messages from "com.test.me" to A1 twice and once to "A2". Messages from "com.test.me.my.Test" would have gone to "A1" twice and "A2" twice.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to