Logger info(String) method in Java with Examples
The info() method of a Logger class 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 lead to a change in state for the application.
There are two types of info() method depending upon no of parameter passed.
- info(String msg): This method is used to forward the string passed as paratemer 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 information we want to pass to logs.
Return value: This method returns nothing.
Below programs illustrate info(String msg) method:
Program 1:
// Java program to demonstrate// Logger.info(String msg) methodimportjava.util.logging.Logger;publicclassGFG {publicstaticvoidmain(String[] args){// Create a LoggerLogger logger= Logger.getLogger(GFG.class.getName());// Call info methodlogger.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 program to demonstrate// Logger.info(String msg) methodimportjava.util.logging.Logger;publicclassGFG {publicstaticvoidmain(String[] args){// Create a LoggerLogger logger= Logger.getLogger("com.api.jar");// Call info methodlogger.info("Welcome to gfg");logger.info("google of codes");}}The output printed on IDE is shown below.
Output:
- 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 program to demonstrate// Logger.info(Supplier) methodimportjava.util.logging.Logger;importjava.util.function.Supplier;publicclassGFG {publicstaticvoidmain(String[] args){// Create a LoggerLogger logger= Logger.getLogger(GFG.class.getName());// Create a supplier<String> methodSupplier<String> StrSupplier= () ->newString("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)
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.


