The fine() method of a Logger class used to Log a FINE message. This method is used to pass FINE types logs to all the registered output Handler objects.
FINE, FINER and FINEST provide tracing information as when what is happening/ has happened in our application. FINE displays the most important messages out of these.
There are two types of fine() method depending upon no of a parameter passed.
-
fine(String msg): This method is used to log a FINE message. If the logger is enabled for logging FINE level message then the given message is forwarded to all the registered output Handler objects.
Syntax:
public void fine(String msg)
Parameters: This method accepts a single parameter String which is the string message.
Return value: This method returns nothing.
Below programs illustrate fine(String msg) method:
Program 1:
// Java program to demonstrate// Logger.fine(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.FINE);// Call fine methodlogger.fine("This is FINE message");}}chevron_rightfilter_noneThe output printed on logs.txt file is shown below.
Output:

-
fine(Supplier msgSupplier): This method is used Log a FINE 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 FINE 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 fine(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 fine(Supplier msgSupplier) method:
Program 1:
// Java program to demonstrate// Logger.fine(String msg) 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.FINE);// Create a supplier<String> methodSupplier<String> StrSupplier= () ->newString("Welcome to GFG");// Call fine(Supplier<String>)logger.fine(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#fine(java.lang.String)
- https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#fine(java.util.function.Supplier)
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- Logger exiting() method in Java with Examples
- Logger entering() method in Java with Examples
- Logger getLevel() method in Java with Examples
- Logger getFilter() Method in Java with Examples
- Logger getHandler() Method in Java with Examples
- Logger getName() Method in Java with Examples
- Logger getResourceBundle() Method in Java with Examples
- Logger getGlobal() Method in Java with Examples
- Logger getParent() Method in Java with Examples
- Logger isLoggable() method in Java with Examples
- Logger getUseParentHandlers() Method in Java with Examples
- Logger getResourceBundleName() 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 setUseParentHandlers() method in Java with Examples
- Logger removeHandler() method in Java with Examples
- Logger setLevel() method in Java with Examples
- Logger config() 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.

