Logger finer() method in Java with Examples
Last Updated :
26 Mar, 2019
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:
import java.io.IOException;
import java.util.logging.*;
public class GFG {
public static void main(String[] args)
throws SecurityException, IOException
{
Logger logger
= Logger.getLogger(
GFG. class .getName());
FileHandler handler
= new FileHandler( "logs.txt" );
handler.setFormatter( new SimpleFormatter());
logger.addHandler(handler);
logger.setLevel(Level.FINER);
logger.finer( "Welcome geeks" );
}
}
|
The 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:
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
{
Logger logger
= Logger.getLogger(
GFG. class .getName());
FileHandler handler
= new FileHandler( "logs.txt" );
handler.setFormatter(
new SimpleFormatter());
logger.addHandler(handler);
logger.setLevel(Level.FINER);
Supplier<String> StrSupplier
= () -> new String( "SET KEY=VALUE" );
logger.finer(StrSupplier);
}
}
|
The output printed on log.txt is shown below.
Output:
References: