Open In App

Logger fine() method in Java with Examples

Improve
Improve
Like Article
Like
Save
Share
Report

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 tracking 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.

  1. 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)
  1. 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




// Java program to demonstrate
// Logger.fine(String msg) method
 
import java.io.IOException;
import java.util.logging.*;
 
public class GFG {
 
    public static void main(String[] args)
        throws SecurityException, IOException
    {
 
        // Create a Logger
        Logger logger
            = Logger.getLogger(
                GFG.class.getName());
 
        // Create a file handler object
        FileHandler handler
            = new FileHandler("logs.txt");
        handler.setFormatter(new SimpleFormatter());
 
        // Add file handler as
        // handler of logs
        logger.addHandler(handler);
 
        // Set Logger level()
        logger.setLevel(Level.FINE);
 
        // Call fine method
        logger.fine("This is FINE message");
    }
}


  1. The output printed on logs.txt file is shown below. Output:
  2. 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)
  1. 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




// Java program to demonstrate
// Logger.fine(String msg) method
 
import java.io.IOException;
import java.util.function.Supplier;
import java.util.logging.*;
 
public class GFG {
 
    public static void main(String[] args)
        throws SecurityException, IOException
    {
 
        // Create a Logger
        Logger logger
            = Logger.getLogger(
                GFG.class.getName());
 
        // Create a file handler object
        FileHandler handler
            = new FileHandler("logs.txt");
        handler.setFormatter(
            new SimpleFormatter());
 
        // Add file handler as
        // handler of logs
        logger.addHandler(handler);
 
        // Set Logger level()
        logger.setLevel(Level.FINE);
 
        // Create a supplier<String> method
        Supplier<String> StrSupplier
            = () -> new String("Welcome to GFG");
 
        // Call fine(Supplier<String>)
        logger.fine(StrSupplier);
    }
}


  1. The output printed on log.txt is shown below. Output:

References:



Last Updated : 11 Apr, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads