The Java Developers Almanac 1.4


Order this book from Amazon.

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

e396. Getting the Log Level of a Logger

The log level of a logger controls how severe a log record must be before the logger accepts it. In particular, a log record whose level is greater than or equal to the logger's log level is logged.

A log level can be null, in which case the level is inherited from the logger's parent.

This example implements a method that returns the level of a logger. If the level is null, the method looks for an ancestor with a non-null level.

    // Return the level of the specified logger.
    // If the level of logger is null, the level of the closest
    // ancestor with a non-null level is returned.
    public static Level getLevel(Logger logger) {
        Level level = logger.getLevel();
        while (level == null && logger.getParent() != null) {
            logger = logger.getParent();
            level = logger.getLevel();
        }
        return level;
     }

 Related Examples
e395. Setting the Log Level of a Logger
e397. Comparing Log Levels
e398. Creating a Custom Log Level

See also: Configuration    File Size    Formatters   


© 2002 Addison-Wesley.