The info() method of a Logger class is used to Log an INFO message. This method is used to forward logs to all the registered output Handler objects.
INFO message: Info is for the use of administrators or advanced users. It denotes mostly the actions that have led to a change in state for the application.
There are two types of info() method depending upon no of parameters passed.
1. info(String msg): This method is used to forward the string passed as a parameter to method to all the registered output Handler objects.
Syntax:
public void info(String msg)
Parameters: This method accepts a single parameter String which is the information we want to pass to logs.
Return value: This method returns nothing.
Below programs illustrate the info(String msg) method:
Program 1:
Java
// Java program to demonstrate // Logger.info(String msg) method import java.util.logging.Logger; public class GFG { public static void main(String[] args) { // Create a Logger Logger logger = Logger.getLogger( GFG. class .getName()); // Call info method logger.info( "This is message 1" ); logger.info( "This is message 2" ); logger.info( "This is message 3" ); logger.info( "This is message 4" ); } } |
The output printed on eclipse ide is shown below.
Output:
Program 2:
Java
// Java program to demonstrate // Logger.info(String msg) method import java.util.logging.Logger; public class GFG { public static void main(String[] args) { // Create a Logger Logger logger = Logger .getLogger( "com.api.jar" ); // Call info method logger.info( "Welcome to gfg" ); logger.info( "google of codes" ); } } |
The output printed on IDE is shown below.
Output:
2. info(Supplier msgSupplier): This method is used Log an INFO 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 INFO 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 info(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 info(String msg) method:
Program 1:
Java
// Java program to demonstrate // Logger.info(Supplier) method import java.util.logging.Logger; import java.util.function.Supplier; public class GFG { public static void main(String[] args) { // Create a Logger Logger logger = Logger.getLogger( GFG. class .getName()); // Create a supplier<String> method Supplier<String> StrSupplier = () -> new String( "Logger logs" ); // Call info(Supplier<String>) logger.info(StrSupplier); } } |
The output printed on eclipse ide is shown below.
Output:
References:
- https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#info(java.lang.String)
- https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#info(java.util.function.Supplier)