The setMessage() method of java.util.logging.LogRecord is used to set the “raw” log message, before localization or formatting for this LogRecord object.we can also set null as raw message.
Syntax:
public void setMessage(String message)
Parameters: This method accepts message which is the raw message string.
Return: This method returns nothing.
Below programs illustrate setMessage() method:
Program 1:
// Java program to illustrate setMessage() method import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.*; public class GFG { public static void main(String[] args) { // Create LogRecord object LogRecord logRecord = new LogRecord( Level.parse( "800" ), "Hi Logger" ); System.out.println( "Previous Message: " + logRecord.getMessage()); // set message of the LogRecord logRecord.setMessage( "GFG Logger" ); // print result System.out.println( "New Message: " + logRecord.getMessage()); } } |
Previous Message: Hi Logger New Message: GFG Logger
Program 2:
// Java program to illustrate setMessage() method import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.*; public class GFG { public static void main(String[] args) { // Create LogRecord object LogRecord logRecord = new LogRecord( Level.INFO, "GFG Logger" ); System.out.println( "Previous Message: " + logRecord.getMessage()); // set message of the LogRecord logRecord.setMessage( null ); // print result System.out.println( "New Message: " + logRecord.getMessage()); } } |
Previous Message: GFG Logger New Message: null
References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/LogRecord.html#setMessage(java.lang.String)