The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.util.logging  [20 examples]

e390. Preventing a Logger from Forwarding Log Records to Its Parent

By default, a logger sends a log record not only to its handlers but to all the handlers of ancestor loggers. If the effects of the parent handlers are not desired, it is necessary to prevent log records from being forwarded to the parent.

This example demonstrates how to stop a logger from sending log records to its parent.

Note: Although the level of a log record is tested against the logger's log level, this test is not done with any of the logger's parents. However, the log level of all handlers is still in effect.

    // Get a logger
    Logger logger = Logger.getLogger("com.mycompany");
    
    // Stop forwarding log records to ancestor handlers
    logger.setUseParentHandlers(false);
    
    // Start forwarding log records to ancestor handlers
    logger.setUseParentHandlers(true);

 Related Examples
e385. The Quintessential Logging Program
e386. Determining If a Message Will Be Logged
e387. Logging a Method Call
e388. Logging an Exception
e389. Minimizing the Impact of Logging Code
e391. Writing Log Records to a Log File
e392. Writing Log Records to Standard Error
e393. Writing Log Records Only After a Condition Occurs
e394. Setting a Filter on a Logger Handler

See also: Configuration    File Size    Formatters    Levels   


© 2002 Addison-Wesley.