1024programmer Java Logger information (string) method in Java, example

Logger information (string) method in Java, example

Logger information (string) method in Java, examples

Original text: https://www . geesforgeks . org/logger-infostring-method-in-Java-with-examples /

The info() method of the Logger class used to log information messages. This method is used to forward logs to all registered output handler objects.

INFO Message: Info is for administrators or advanced users. It mainly represents operations that result in changes to the application state.

There are two types of info() methods depending on the number of parameters passed.

  1. Message (String Message): This method is used to forward the string passed as the paratemer to method to all registered output Handler objects.

Syntax:

public void info( String msg)

Parameters: This method accepts a single argument string, which is the information we want to pass to the log.

Return value:This method does not return anything.

The following program illustrates the message (string message) method:

Program 1:

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

eclipse IDE is shown below.
Output:

Program 2:

// 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 the IDE is as follows.
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:

    “`java
    public void info(Supplier msgSupplier)

    ““

    Parameters :This method accepts a single parameter msgSupplier, which is a function that, when called, will produce the desired log message.

    Return value:This method does not return anything.

    The following program description information (string message) 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 method
    Supplier StrSupplier
    = () -> new String(“Logger logs”);

    // Call info(Supplier)
         logger.info(StrSupplier);
      }
    }
    “`

    The output printed on the eclipse ide is as follows.
    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)

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/logger-information-string-method-in-java-example/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索