Saturday, November 22, 2025
HomeLanguagesJavaLogger isLoggable() method in Java with Examples

Logger isLoggable() method in Java with Examples

isLoggable() method of a Logger class is used to return a response in boolean value which provides an answer to the query that if a message of the given level would actually be logged by this logger or not. This check is based on the Loggers effective level, which may be inherited from its parent.

Syntax:

public boolean isLoggable(Level level)

Parameters: This method accepts one parameter level which represents message logging level.

Return value: This method returns true if the given message level is currently being logged.

Below programs illustrate the isLoggable() method:

Program 1:




// Java program to demonstrate
// Logger.isLoggable() method
  
import java.util.logging.*;
  
public class GFG {
  
    private static Logger logger
        = Logger.getLogger(
            GFG.class.getName());
  
    public static void main(String args[])
    {
  
        // Check if the Level.INFO
        // is currently being logged.
        boolean flag
            = logger.isLoggable(
                Level.INFO);
  
        // Print value
        System.out.println("The Level.INFO"
                           + " is currently being logged - "
                           + flag);
    }
}


Output:

The Level.INFO is currently being logged - true

Program 2:




// Java program to demonstrate
// Logger.isLoggable() method
  
import java.util.logging.*;
  
public class GFG {
  
    private static Logger logger
        = Logger.getLogger(
            GFG.class.getName());
  
    public static void main(String args[])
    {
  
        // Check if the Level.OFF
        // is currently being logged.
        boolean flag
            = logger.isLoggable(Level.OFF);
  
        // Print value
        System.out.println("The Level.OFF"
                           + " is currently being logged - "
                           + flag);
    }
}


Output:

The Level.OFF is currently being logged - true

Reference: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#isLoggable(java.util.logging.Level)

RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11931 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6848 POSTS0 COMMENTS