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 Ashish Kulkarni <as...@gmail.com> on 2007/08/23 22:24:42 UTC
Question about logging to multiple files
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
<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>
<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>
Re: Question about logging to multiple files
Posted by Ashish Kulkarni <as...@gmail.com>.
Hi
Work perfect, thank you
On 8/23/07, James A. N. Stauffer <st...@gmail.com> wrote:
>
> You probably don't want to put the A2 appender in the root section.
> Also if you set additivity="false" in the com.test.me.my.Test
> catagory/logger then the message won't go to the A1 appender.
>
> On 8/23/07, Ashish Kulkarni <as...@gmail.com> 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
> >
> > <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>
> >
> > <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>
> >
>
>
> --
> James A. N. Stauffer http://www.geocities.com/stauffer_james/
> Are you good? Take the test at http://www.livingwaters.com/good/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
Re: Question about logging to multiple files
Posted by "James A. N. Stauffer" <st...@gmail.com>.
You probably don't want to put the A2 appender in the root section.
Also if you set additivity="false" in the com.test.me.my.Test
catagory/logger then the message won't go to the A1 appender.
On 8/23/07, Ashish Kulkarni <as...@gmail.com> 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
>
> <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>
>
> <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>
>
--
James A. N. Stauffer http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Question about logging to multiple files
Posted by "James A. N. Stauffer" <st...@gmail.com>.
You still need to set additivity. I *think* it is:
log4j.additivity.com.test.me.my.Test=false
Also I think you may be defining you loggers incorrectly but I'm not sure.
On 8/23/07, Ashish Kulkarni <as...@gmail.com> wrote:
> Hi
> This works fine, can i do the same if i am using properties file instead of
> XML file for defining configuration
> some thing like
>
> log4j.rootLogger= A1
>
> log4j.appender.A1=org.apache.log4j.ConsoleAppender
> # A1 uses PatternLayout.
> log4j.appender.A1.layout=org.apache.log4j.PatternLayout
> log4j.appender.A1.layout.ConversionPattern=%d %-5p [%t] %-17c{2} (%13F:%L)
> %3x - %m%n
> log4j.appender.A1.com.test.me=DEBUG
>
>
> log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender
> log4j.appender.A2.File=${java.io.tmpdir}approvals6000F3.txt
> log4j.appender.A2.Append=false
> log4j.appender.A2.DatePattern='.'yyyy-MM-dd
> log4j.appender.A2.layout=org.apache.log4j.PatternLayout
> log4j.appender.A2.layout.ConversionPattern=%-5r %-5p [%t] %c{2} - %m%n
> log4j.appender.A2.com.test.me.my.Test=DEBUG
>
> The way i have written in above properties file, will it work as expected?
>
>
> Ashish
>
>
>
> On 8/23/07, Curt Arnold <ca...@apache.org> wrote:
> >
> >
> > 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: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
> >
>
--
James A. N. Stauffer http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Question about logging to multiple files
Posted by Ashish Kulkarni <as...@gmail.com>.
Hi
This works fine, can i do the same if i am using properties file instead of
XML file for defining configuration
some thing like
log4j.rootLogger= A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d %-5p [%t] %-17c{2} (%13F:%L)
%3x - %m%n
log4j.appender.A1.com.test.me=DEBUG
log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A2.File=${java.io.tmpdir}approvals6000F3.txt
log4j.appender.A2.Append=false
log4j.appender.A2.DatePattern='.'yyyy-MM-dd
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%-5r %-5p [%t] %c{2} - %m%n
log4j.appender.A2.com.test.me.my.Test=DEBUG
The way i have written in above properties file, will it work as expected?
Ashish
On 8/23/07, Curt Arnold <ca...@apache.org> wrote:
>
>
> 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: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
Re: Question about logging to multiple files
Posted by Curt Arnold <ca...@apache.org>.
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: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org