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:
import java.util.logging.Level;
import java.util.logging.LogRecord;
public class GFG {
public static void main(String[] args)
{
LogRecord logRecord = new LogRecord(
Level.parse( "400" ),
"Hi message" );
String message = logRecord.getMessage();
System.out.println( "Message of Log Record = "
+ message);
}
}
|
Output:
Message of Log Record = Hi message
Program 2:
import java.util.logging.Level;
import java.util.logging.LogRecord;
public class GFG {
public static void main(String[] args)
{
LogRecord logRecord = new LogRecord(
Level.parse( "WARNING" ),
"Some Warning Message" );
String message = logRecord.getMessage();
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
Share your thoughts in the comments
Please Login to comment...