Hi Roy,
Firstly, the debug="true" setting in the top level log4j:configuration node is what is causing log4j to output stuff to the console as it's configured. It's useful if one is not quite sure what is going on in configuration, but usually it's best to leave this to false.
Secondly, you are suffering from a feature of log4j that often gets people a little confused. Here's what happens:
* You log something as the DEBUG level to "com.mypackage"
* log4j inspects this event, verifies that it is at least greater than or equal to the entire log4j threshold setting (debug by default) , it then verifies that the event is greater than or equal to the specific logger's level (in your case it is, because com.mypackage is set to debug)
* If this event is ok to append for the hierachy threshold and logger level, it appends to any appender attached to the logger com.mypackage, AND ANY appender attached to the loggers up the hierachy. ('com' and the rootLogger in this example). This is known as the additivity setting, which is true by default. It doesn't matter if the parent logger's have a different level setting.
You will probably have another symptom that those DEBUG/INFO/WARN statements that you didn't want in your StdOut are probably appearing twice. This is because the appender is attached to both the com.mypackage logger, and the rootLogger, and therefore gets logged via this appender additivity setting.
More about this here: http://logging.apache.org/log4j/docs/manual.html (see the Appender additivity section)
What I would suggest is one of 2 strategies:
1) * change
<logger name="com.mypackage">
to be <logger name="com.mypackage" additivity="false">
* and then decide whether you want any of the com.mypackage events to go to stdout, if not, remove the appender-ref in com.mypackage.
OR
2) Add a Level match filter to the stdout appender so that only ERROR's ever go there, regardless of the source of them. See more here: http://logging.apache.org/log4j/docs/faq.html (item 2.9) for some info on LevelMatchFilter usage. This won't stop ERROR's from com.mypackage.* from appearing twice, because of the additivity rule.
Hope this helps,
cheers,
Paul Smith
[EMAIL PROTECTED] wrote:
Hi guys,
Looking for some help. I've searched the archives and I'm still confused. I've been struggling to get my logging through log4j.xml. I use logging in my Tomcat web apps and also in standalone applications.
So far my configuration file looks like this: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true"> <appender name="std-out" class="org.apache.log4j.ConsoleAppender"> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/> </layout> </appender>
<appender name="error-out" class="org.apache.log4j.DailyRollingFileAppender"> <param name="File" value="error.log"/> <param name="Threshold" value="error"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/> </layout> </appender>
<appender name="debug-out" class="org.apache.log4j.DailyRollingFileAppender"> <param name="File" value="debug.log"/> <param name="Threshold" value="debug"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/> </layout> </appender>
<logger name="com.mypackage">
<level value="debug"/>
<appender-ref ref="std-out" />
<appender-ref ref="error-out" />
<appender-ref ref="debug-out" />
</logger>
<root>
<level value="error"/>
<appender-ref ref="std-out" />
</root>
</log4j:configuration>
If I have the <root>'s level set to "error" shouldn't I only be seeing "error" logs?
I'm also seeing log4j logs: log4j: Threshold ="null". log4j: Retreiving an instance of org.apache.log4j.Logger. log4j: Setting [com.mypackage] additivity to [true]. log4j: Level value for com.mypackage is [debug]. log4j: com.mypackage level set to DEBUG etc...
Why am I seeing this and how can I avoid it?
Thanks!
Roy.
--------------------------------------------------------------------- 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]
