previous next TOC
Second MyApp example (3 of 4)

Here is a configuration file that suppresses the debugging output from any component in the com.foo package.
 
log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout

# Print the date in ISO 8601 format
log4j.appender.A1.layout.ConversionPattern=%d %p %m%n

# Print only messages of level WARN or above in
# the package com.foo.
log4j.logger.com.foo=WARN
 
MyApp configured with this file results in:

2001-03-12 14:07:41,508 INFO Entering application.
2001-03-12 14:07:41,529 INFO Exiting application.


As the logger com.foo.Bar does not have an assigned level, it inherits its priority from com.foo, which was set to WARN in the configuration file. The log statement from the Bar.doIt method has the level DEBUG, lower than the logger level WARN. Consequently, the doIt method's log request is suppressed.

 

GET THE DOCS DIRECTLY FROM THE DEVELOPER
For up to date and detailed log4j documentation directly from the developer please consider The complete log4j manual.