Logger finer() method in Java with Examples
The finer() method of a Logger class used to Log an FINER message.This method is used to pass FINER types logs to all the registered output Handler objects.
FINER message: FINER outputs a detailed tracing message and may include logging calls regarding method entering, exiting, throwing exceptions.
There are two types of finer() method depending upon the number of parameters passed.
-
finer(String msg): This method is used to log a FINER message.If the logger is enabled for logging FINER level message then the given message is forwarded to all the registered output Handler objects.
Syntax:
public void finer(String msg)
Parameters: This method accepts a single parameter String which is the string message.
Return value: This method returns nothing.
Below programs illustrate finer(String msg) method:
Program 1:
// Java program to demonstrate// Logger.finer(String msg) methodimportjava.io.IOException;importjava.util.logging.*;publicclassGFG {publicstaticvoidmain(String[] args)throwsSecurityException, IOException{// Create a LoggerLogger logger= Logger.getLogger(GFG.class.getName());// Create a file handler objectFileHandler handler=newFileHandler("logs.txt");handler.setFormatter(newSimpleFormatter());// Add file handler as// handler of logslogger.addHandler(handler);// Set Logger level()logger.setLevel(Level.FINER);// Call finer methodlogger.finer("Welcome geeks");}}chevron_rightfilter_noneThe output printed on logs.txt file is shown below.
Output:

-
finer(Supplier msgSupplier): This method is used Log a FINER message, constructed only if the logging level is such that the message will actually be logged. It means If the logger is enabled for the FINER message level then the message is constructed by invoking the provided supplier function and forwarded to all the registered output Handler objects.
Syntax:
public void finer(Supplier msgSupplier)
Parameters: This method accepts a single parameter msgSupplier which is a function, which when called, produces the desired log message.
Return value: This method returns nothing.
Below programs illustrate finer(Supplier msgSupplier) method:
Program 1:// Java program to demonstrate// Logger.finer(Supplier<String>) methodimportjava.io.IOException;importjava.util.function.Supplier;importjava.util.logging.*;publicclassGFG {publicstaticvoidmain(String[] args)throwsSecurityException, IOException{// Create a LoggerLogger logger= Logger.getLogger(GFG.class.getName());// Create a file handler objectFileHandler handler=newFileHandler("logs.txt");handler.setFormatter(newSimpleFormatter());// Add file handler as// handler of logslogger.addHandler(handler);// Set Logger level()logger.setLevel(Level.FINER);// Create a supplier<String> methodSupplier<String> StrSupplier= () ->newString("SET KEY=VALUE");// Call finer(Supplier<String>)logger.finer(StrSupplier);}}chevron_rightfilter_noneThe output printed on log.txt is shown below.
Output:
References:
- https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#finer(java.lang.String)
- https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#finer(java.util.function.Supplier)
- Logger log() Method in Java with Examples
- Logger fine() method in Java with Examples
- Logger getLevel() method in Java with Examples
- Logger config() method in Java with Examples
- Logger throwing() 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 getLogger() 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
Recommended Posts:
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.



