
In my webapp I am trying to send emails only on errors, with everything else logged to a file. I am using logback under slf4j, with the log4j/slf4j bridge for the external libraries that normally use log4j. My configuration file is reloaded in the servlet context init (using the Joran configurator example from the documentation) so I can set some system properties used in the appenders (like the context name). The logging config has : <root level="ERROR"> <appender-ref ref="EMAIL" /> <appender-ref ref="FILE" /> </root> <logger name="foo" level="DEBUG"> <appender-ref ref="FILE" /> </logger> *Everything* not of log level ERROR coming from foo is getting logged twice. Why? I've pored over Chapter 2 of the documentation and it seems to describe the opposite of what is happening. The level for foo will ideally swap between DEBUG and INFO, but I can't have things logged twice all the time. How do I fix this? Thanks Chris

Hello Chris, As Robert mentioned, appenders are inherited cumulatively from the logger tree, unless the additivity flag of a given logger is set to false. Since you have set the bufferSize of SMTPAppender (as mentioned in a previous message), setting the root logger level to DEBUG and attaching both EMAIL and FILE appender to it should cover your needs. For example, <root level="DEBUG"> <appender-ref ref="EMAIL" /> <appender-ref ref="FILE" /> </root> HTH, Chris Cheshire wrote:
In my webapp I am trying to send emails only on errors, with everything else logged to a file. I am using logback under slf4j, with the log4j/slf4j bridge for the external libraries that normally use log4j.
My configuration file is reloaded in the servlet context init (using the Joran configurator example from the documentation) so I can set some system properties used in the appenders (like the context name).
The logging config has :
<root level="ERROR"> <appender-ref ref="EMAIL" /> <appender-ref ref="FILE" /> </root>
<logger name="foo" level="DEBUG"> <appender-ref ref="FILE" /> </logger>
*Everything* not of log level ERROR coming from foo is getting logged twice. Why? I've pored over Chapter 2 of the documentation and it seems to describe the opposite of what is happening. The level for foo will ideally swap between DEBUG and INFO, but I can't have things logged twice all the time. How do I fix this?
Thanks
Chris
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch

Ceki, What I want is only ERROR logging from the external libraries (eg Stripes), while having DEBUG from my own. Do I need to define it as : <root level="ERROR"> <appender-ref ref="EMAIL" /> </root> <logger name="foo" level="DEBUG" additivity="false"> <appender-ref ref="EMAIL" /> <appender-ref ref="FILE" /> </logger> Regarding the additivity, why are INFO messages being logged by the root logger when its threshold is ERROR? Shouldn't it just be ERROR getting picked up by that section, even with the additivity on? Thanks Chris On Mon, Dec 1, 2008 at 3:48 AM, Ceki Gulcu <ceki@qos.ch> wrote:
Hello Chris,
As Robert mentioned, appenders are inherited cumulatively from the logger tree, unless the additivity flag of a given logger is set to false.
Since you have set the bufferSize of SMTPAppender (as mentioned in a previous message), setting the root logger level to DEBUG and attaching both EMAIL and FILE appender to it should cover your needs. For example,
<root level="DEBUG"> <appender-ref ref="EMAIL" /> <appender-ref ref="FILE" /> </root>
HTH,
Chris Cheshire wrote:
In my webapp I am trying to send emails only on errors, with everything else logged to a file. I am using logback under slf4j, with the log4j/slf4j bridge for the external libraries that normally use log4j.
My configuration file is reloaded in the servlet context init (using the Joran configurator example from the documentation) so I can set some system properties used in the appenders (like the context name).
The logging config has :
<root level="ERROR"> <appender-ref ref="EMAIL" /> <appender-ref ref="FILE" /> </root>
<logger name="foo" level="DEBUG"> <appender-ref ref="FILE" /> </logger>
*Everything* not of log level ERROR coming from foo is getting logged twice. Why? I've pored over Chapter 2 of the documentation and it seems to describe the opposite of what is happening. The level for foo will ideally swap between DEBUG and INFO, but I can't have things logged twice all the time. How do I fix this?
Thanks
Chris
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

Chris Cheshire wrote:
Ceki,
What I want is only ERROR logging from the external libraries (eg Stripes), while having DEBUG from my own.
In that case, you need to write <root level="ERROR"> <appender-ref ref="EMAIL" /> <appender-ref ref="FILE" /> </root> <logger name="package.of.for.your.own.code" level="DEBUG"/>
Do I need to define it as :
<root level="ERROR"> <appender-ref ref="EMAIL" /> </root>
<logger name="foo" level="DEBUG" additivity="false"> <appender-ref ref="EMAIL" /> <appender-ref ref="FILE" /> </logger>
Regarding the additivity, why are INFO messages being logged by the root logger when its threshold is ERROR? Shouldn't it just be ERROR getting picked up by that section, even with the additivity on?
The level setting for the root logger is inherited. When you set the level of the "foo" loggger to DEBUG, you override the level setting of the root logger. This is explained in the manual http://logback.qos.ch/manual/architecture.html#basic_selection HTH, -- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch

Thanks Ceki, this all helps :) On Mon, Dec 1, 2008 at 11:56 AM, Ceki Gulcu <ceki@qos.ch> wrote:
Chris Cheshire wrote:
Ceki,
What I want is only ERROR logging from the external libraries (eg Stripes), while having DEBUG from my own.
In that case, you need to write
<root level="ERROR"> <appender-ref ref="EMAIL" /> <appender-ref ref="FILE" /> </root>
<logger name="package.of.for.your.own.code" level="DEBUG"/>
Do I need to define it as :
<root level="ERROR"> <appender-ref ref="EMAIL" /> </root>
<logger name="foo" level="DEBUG" additivity="false"> <appender-ref ref="EMAIL" /> <appender-ref ref="FILE" /> </logger>
Regarding the additivity, why are INFO messages being logged by the root logger when its threshold is ERROR? Shouldn't it just be ERROR getting picked up by that section, even with the additivity on?
The level setting for the root logger is inherited. When you set the level of the "foo" loggger to DEBUG, you override the level setting of the root logger.
This is explained in the manual
http://logback.qos.ch/manual/architecture.html#basic_selection
HTH, -- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user
participants (2)
-
Ceki Gulcu
-
Chris Cheshire