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; }

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.