Thursday, June 18, 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

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6898 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6965 POSTS0 COMMENTS