Friday, February 6, 2026
HomeLanguagesJavaLogRecord getMessage() method in Java with Examples

LogRecord getMessage() method in Java with Examples

The getMessage() method of java.util.logging.LogRecord is used to get the actual log message, before localization or formatting from this logRecord.This message may be null, which is equivalent to the empty string “”. This returned message may be either the final text or a localization key.

Syntax:

public String getMessage()

Parameters: This method accepts nothing.

Return: This method returns the raw message string.

Below programs illustrate getMessage() method:
Program 1:




// Java program to illustrate getMessage() 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"),
            "Hi message");
  
        // get message of LogRecord
        String message = logRecord.getMessage();
  
        // print result
        System.out.println("Message of Log Record = "
                           + message);
    }
}


Output:

Message of Log Record = Hi message

Program 2:




// Java program to illustrate getMessage() 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("WARNING"),
            "Some Warning Message");
  
        // get message of LogRecord
        String message = logRecord.getMessage();
  
        // print result
        System.out.println("Message of Log Record = "
                           + message);
    }
}


Output:

Message of Log Record = Some Warning Message

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

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

1 COMMENT

Most Popular

Dominic
32489 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6862 POSTS0 COMMENTS
Nicole Veronica
11983 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12073 POSTS0 COMMENTS
Shaida Kate Naidoo
6995 POSTS0 COMMENTS
Ted Musemwa
7236 POSTS0 COMMENTS
Thapelo Manthata
6946 POSTS0 COMMENTS
Umr Jansen
6930 POSTS0 COMMENTS