LogRecord getSourceMethodName() method in Java with Examples
Last Updated :
23 Oct, 2019
The getSourceMethodName() method of java.lang.reflect.LogRecord is used to get the name of the method that allegedly issued the logging request. The source method which is used in logRecord for logging purpose.
Syntax:
public String getSourceMethodName()
Parameters: This method accepts nothing.
Return: This method returns the source method name.
Below programs illustrate getSourceMethodName() 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( "800" ),
"Hi Logger" );
logRecord.setSourceMethodName(
"MyFirstSourceMethod" );
String sourceMethod
= logRecord.getSourceMethodName();
System.out.println(
"Source Method Name = "
+ sourceMethod);
}
}
|
Output:
Source Method Name = MyFirstSourceMethod
Program 2:
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.*;
public class GFG {
public static void main(String[] args)
{
LogRecord logRecord = new LogRecord(
Level.parse( "600" ),
"GFG Logger" );
logRecord.setSourceMethodName(
ArrayList
. class
.getMethods()[ 0 ]
.getName());
String sourceMethod
= logRecord.getSourceMethodName();
System.out.println(
"Source Method Name = "
+ sourceMethod);
}
}
|
Output:
Source Method Name = add
References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/LogRecord.html#getSourceMethodName()
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...