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.



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

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // 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");
        }
    }

    chevron_right

    
    

    The output printed on eclipse ide is shown below.
    Output:

    Program 2:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // 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");
        }
    }

    chevron_right

    
    

    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:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // 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);
        }
    }

    chevron_right

    
    

    The output printed on eclipse ide is shown below.
    Output:

References:



My Personal Notes arrow_drop_up

I am a Developer I love to code and bring my ideas alive

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.