At 07:19 PM 9/17/2006, you wrote:
Dear Bender,
Thanks four your xml sample now it works as I
expect, on the attached file you will find it.
Nevertheless I have some comments, I am not
log4j expert, but I guess the syntax could be
simplified, and probably it is possible:
1. With your suggestion, I have to specify
explicit each external library, but the opossite
would be easier to define, but I don't know how
to set it, all my classes belong to the package:
com.schinvest, so this package will be at INFO
level for console, file, and htmlFile, any thing
else will have WARNING level for all appenders.
Probably this could be configurate in simpler
way, but I don't know how to do it.
2. On cathegory node there is no way on the
class attribute to specify more than one class at the same time, is that true?
<category name="org, net.sf">
<level value="warn"></level>
<appender-ref ref="file"/>
<appender-ref ref="htmlFile"/>
</category>
so this cathegory will be applied for org.* and
net.sf.* packages, that would simplify the log4
configuration, but I have tested it and it doesn't work.
First, you should be using <logger>, not
<category>. And it's <level value="warn"/>, not <level value="warn"></level>
Otherwise, Interesting idea. It won't work and I
doubt very much that this will be added to
Log4j-1.2.xx, but it might be something for later
versions. You could post an enhancement report in bugzilla.
Your only real chance to get this behavior
currently is to set everything in the <root>
logger. In fact, I usually set most everything
in the <root> logger and only define other
loggers if I want behavior in any way different
than what I set in the <root> logger. Also, I
usually set the <root> logger to <level
value="warn"/> and specify a lower level only when I truly need it.
Below is how I would envision your config
file. I think you'll find it 100% more
manageable. By defaulting to a higher level
"warn" in <root>, you can then make an exception
for your own organization's package instead of
having to exhaustively account for all the
external packages your application
uses. Generalize the unknown (external library
config) and specify the known (your organization's config)....
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration
xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="stdout"
class="org.apache.log4j.ConsoleAppender">
<param name="target" value="System.out"/>
<param name="ImmediateFlush" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%5p%x[%M](%C{1}:%L) - %m%n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="info"/>
<param name="LevelMax" value="fatal"/>
<param name="AcceptOnMatch" value="false"/>
</filter>
</appender>
<appender name="file"
class="org.apache.log4j.DailyRollingFileAppender">
<!--param name="target" value="System.err"/-->
<param name="File" value="log/lra.log"/>
<param name="Append" value="false"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="[%d{yyyy-MM-dd
hh:mm:ss},%6.6r]%5p%x[%M](%C{1}:%L) - %m%n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="debug"/>
<param name="LevelMax" value="fatal"/>
<param name="AcceptOnMatch" value="false"/>
</filter>
</appender>
<appender name="htmlFile"
class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="log/lra_log.html"/>
<param name="Append" value="false"/>
<layout class="org.apache.log4j.HTMLLayout">
<param name="Title" value="LRA log Information"/>
<param name="LocationInfo" value="true"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="info"/>
<param name="LevelMax" value="fatal"/>
<param name="AcceptOnMatch" value="false"/>
</filter>
</appender>
<logger name="com.mypackage">
<level value="debug"/>
</logger>
<root>
<level value="warn"/>
<appender-ref ref="stdout"/>
<appender-ref ref="file"/>
<appender-ref ref="htmlFile"/>
</root>
</log4j:configuration>
Jake
Thanks for your help,
David
Bender Heri <[EMAIL PROTECTED]> wrote:
Here is an example of an xml configuration which
uses filters (BTW: Using this two appenders when
debugging in eclipse the console shows the DEBUG
and INFO in black color and the others in red
color). You can also write your own filter class
where you are free to filter what you want. Be
careful on the ordering when extending this xml
file. The logj4 parser expects first all appenders followed by all loggers.
<?xml version = "1.0" encoding = "UTF-8"?>
<?xml:namespace prefix = log4j />
Yahoo! Messenger with Voice.
<http://us.rd.yahoo.com/mail_us/taglines/postman1/*http://us.rd.yahoo.com/evt=39663/*http://voice.yahoo.com>Make
PC-to-Phone Calls to the US (and 30+ countries) for 2ยข/min or less.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--
This configuration defines three appenders:
console: With warn level
file: With debug level four all classes except for external libraries of
our application.
htmlFile: With the same configuration as console, except for HTML format.
-->
<log4j:configuration
xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="stdout"
class="org.apache.log4j.ConsoleAppender">
<param name="target" value="System.out"/>
<param name="ImmediateFlush" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%5p%x[%M](%C{1}:%L) - %m%n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="info"/>
<param name="LevelMax" value="fatal"/>
<param name="AcceptOnMatch" value="false"/>
</filter>
</appender>
<appender name="file"
class="org.apache.log4j.DailyRollingFileAppender">
<!--param name="target" value="System.err"/-->
<param name="File" value="log/lra.log"/>
<param name="Append" value="false"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="[%d{yyyy-MM-dd
hh:mm:ss},%6.6r]%5p%x[%M](%C{1}:%L) - %m%n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="debug"/>
<param name="LevelMax" value="fatal"/>
<param name="AcceptOnMatch" value="false"/>
</filter>
</appender>
<appender name="htmlFile"
class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="log/lra_log.html"/>
<param name="Append" value="false"/>
<layout class="org.apache.log4j.HTMLLayout">
<param name="Title" value="LRA log Information"/>
<param name="LocationInfo" value="true"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="info"/>
<param name="LevelMax" value="fatal"/>
<param name="AcceptOnMatch" value="false"/>
</filter>
</appender>
<!--We filter now by classes setting the
main pattern on the name attribute
Note: You can't concatenate the class names on one category, for example:
putting in the name="org, net.sf" together.-->
<category name="org">
<level value="warn"></level>
<appender-ref ref="file"/>
<appender-ref ref="htmlFile"/>
</category>
<category name="net.sf">
<level value="warn"></level>
<appender-ref ref="file"/>
<appender-ref ref="htmlFile"/>
</category>
<category name="oracle">
<level value="warn"></level>
<appender-ref ref="file"/>
<appender-ref ref="htmlFile"/>
</category>
<category name="com.OsterMiller">
<level value="warn"></level>
<appender-ref ref="file"/>
<appender-ref ref="htmlFile"/>
</category>
<category name="com.keypoint">
<level value="warn"></level>
<appender-ref ref="file"/>
<appender-ref ref="htmlFile"/>
</category>
<category name="javax.servlet, javax.transaction">
<level value="warn"></level>
<appender-ref ref="file"/>
<appender-ref ref="htmlFile"/>
</category>
<root>
<level value="debug"/>
<appender-ref ref="stdout"/>
<appender-ref ref="file"/>
<appender-ref ref="htmlFile"/>
</root>
</log4j:configuration>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]