logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ashish Kulkarni" <ashish.kulkarn...@gmail.com>
Subject Re: Question about logging to multiple files
Date Thu, 23 Aug 2007 21:01:21 GMT
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 <carnold@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
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message