Open In App

LogRecord getMessage() method in Java with Examples

Improve
Improve
Like Article
Like
Save
Share
Report

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()



Last Updated : 14 Oct, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads