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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

Message of Log Record = Hi message

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

Message of Log Record = Some Warning Message

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




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.