logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curt Arnold <carn...@apache.org>
Subject Re: DEBUG messages appearing on console?
Date Tue, 02 Sep 2008 20:47:20 GMT

On Sep 2, 2008, at 2:00 PM, Patrick.Grimard@xtl.com wrote:

>
> I'm trying to configure log4j so that DEBUG messages or lower  
> priority only
> appear in a log file and not the console, and anything above DEBUG  
> appears on
> the console.  This is what my log4j.properties file looks like right  
> now,
> however the DEBUG messages are still appearing on the console.  I'm  
> using log4j
> along with Commons Logging API if that makes any difference.
>
> # Set the root logger to the INFO level and CA to be it's appender
> log4j.rootLogger=WARN, CA
> log4j.appender.CA=org.apache.log4j.ConsoleAppender
> log4j.appender.CA.layout=org.apache.log4j.PatternLayout
> log4j.appender.CA.layout.ConversionPattern=%-5p %d{yyyy-MM-dd  
> HH:mm:ss} [%t]
> %c%n\t{%m}%n%n
>
> # LinkHarvester
> log4j.logger.com.dsn.loadlink=DEBUG, harvester
> log4j.appender.harvester=org.apache.log4j.RollingFileAppender
> log4j.appender.harvester.File=C:/log4j/logs/LinkHarvester.log
> log4j.appender.harvester.MaxFileSize=100KB
> log4j.appender.harvester.MaxBackupIndex=1
> log4j.appender.harvester.layout=org.apache.log4j.PatternLayout
> log4j.appender.harvester.layout.ConversionPattern=%-5p %d{yyyy-MM-dd  
> HH:mm:ss}
> [%t] %c%n\t{%m}%n%n

The filter suggestion is a bit overkill for what you need.

What is happening is that you are assigning a DEBUG threshold to all  
logging requests to loggers starting with "com.dsn.loadlink", all  
other loggers have a threshold of WARN.  You are also attaching a  
ConsoleAppender to the root logger and a RollingFileAppender to  
"com.dsn.loadlink", but that is an independent action from setting the  
thresholds.

So if you make a logging request on "com.dsn.loadlink" or a child  
logger, it is evaluated against the nearest specified threshold and if  
that is satisfied, then it is processed by all appenders attached in  
the hierarchy (unless additivity is set to false which will prevent  
appenders attached to parent loggers from seeing the event).  You can  
set a threshold on the appender which is independent of the threshold  
on the logger.

Unless you have a specific need to separate the appenders, I would  
attach them both to root, but set a threshold on the ConsoleAppender.


> log4j.rootLogger=DEBUB, CA, harvester
> log4j.appender.CA=org.apache.log4j.ConsoleAppender
> log4j.appender.CA.layout=org.apache.log4j.PatternLayout
> log4j.appender.CA.layout.ConversionPattern=%-5p %d{yyyy-MM-dd  
> HH:mm:ss} [%t]
> %c%n\t{%m}%n%n
log4j.appender.threshold=INFO
> log4j.appender.harvester=org.apache.log4j.RollingFileAppender
> log4j.appender.harvester.File=C:/log4j/logs/LinkHarvester.log
> log4j.appender.harvester.MaxFileSize=100KB
> log4j.appender.harvester.MaxBackupIndex=1
> log4j.appender.harvester.layout=org.apache.log4j.PatternLayout
> log4j.appender.harvester.layout.ConversionPattern=%-5p %d{yyyy-MM-dd  
> HH:mm:ss}
> [%t] %c%n\t{%m}%n%n
>



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message