LogRecord getParameters() method in Java with Examples

The getParameters() method of java.lang.reflect.LogRecord is used to get the parameters to the log message.These parameters are the parameters to be inserted into the message of this LogRecord.

Syntax:

public Object[] getParameters()

Parameters: This method accepts nothing.



Return: This method returns the log message parameters.It can be null if there are no parameters to return.

Below programs illustrate getParameters() method:
Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to illustrate
// getParameters() method
  
import java.util.logging.Level;
import java.util.logging.LogRecord;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Create LogRecord object
        LogRecord logRecord = new LogRecord(
            Level.parse("800"),
            "Hi Logger");
  
        logRecord.setParameters(
            new Object[] {});
  
        // get object parameters
        Object[] params
            = logRecord.getParameters();
  
        System.out.println(
            "Object Array length: "
            + params.length);
    }
}

chevron_right


Output:

Object Array length: 0

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to illustrate
// getParameters() method
  
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.LogRecord;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Create LogRecord object
        LogRecord logRecord = new LogRecord(
            Level.parse("400"),
            "GFG logger");
  
        Object[] objArr
            = String
                  .class
                  .getDeclaredMethods()[4]
                  .getParameters();
        logRecord.setParameters(objArr);
  
        // get object parameters
        Object[] params
            = logRecord.getParameters();
  
        for (int i = 0; i < params.length; i++) {
            System.out.println(params[i]);
        }
    }
}

chevron_right


Output:

java.lang.Object arg0

References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/LogRecord.html#getParameters()



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.