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); } } |
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); } } |
The Level.OFF is currently being logged - true
Recommended Posts:
- Logger log() Method in Java with Examples
- Logger fine() method in Java with Examples
- Logger config() method in Java with Examples
- Logger throwing() method in Java with Examples
- Logger getLogger() Method in Java with Examples
- Logger getHandler() Method in Java with Examples
- Logger getAnonymousLogger() Method in Java with Examples
- Logger getFilter() Method in Java with Examples
- Logger getLevel() method in Java with Examples
- Logger setFilter() method in Java with Examples
- Logger addHandler() method in Java with Examples
- Logger setResourceBundle() method in Java with Examples
- Logger setParent() method in Java with Examples
- Logger getResourceBundleName() method in Java with Examples
- Logger setLevel() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



