Thursday, May 14, 2026
HomeLanguagesJavaLogRecord setParameters() method in Java with Examples

LogRecord setParameters() method in Java with Examples

The setParameters() method of java.util.logging.LogRecord is used to set the parameters to the log message.These parameters are the parameters to be inserted into the message of this LogRecord.

Syntax:

public void setParameters(Object[] parameters)

Parameters: This method accepts parameters as parameter which are the log message parameters in the form of Object[].

Return: This method returns nothing.

Below programs illustrate setParameters() method:
Program 1:




// Java program to illustrate setParameters() 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");
  
        // set empty object array
        logRecord.setParameters(new Object[] {});
  
        System.out.println(
            "Object Array length: "
            + logRecord.getParameters().length);
    }
}


Output:

Object Array length: 0

Program 2:




// Java program to illustrate setParameters() 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("800"),
            "Hi Logger");
  
        // get parameter object array
        // from string class method
        Method method
            = String.class.getDeclaredMethods()[4];
        System.out.println("Method : "
                           + method.getName());
        Object[] objArr
            = method.getParameters();
  
        // set empty object array
        logRecord.setParameters(objArr);
  
        // get array
        Object[] array = logRecord.getParameters();
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }
    }
}


Output:

Method : compareTo
java.lang.Object arg0

References: https://docs.oracle.com/javase/8/docs/api/java/util/logging/LogRecord.html#setParameters-java.lang.Object:A-

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS