LogRecord setSourceMethodName() method in Java with Examples
The setSourceMethodName() method of java.util.logging.LogRecord is used to set the name of the method that allegedly issued the logging request. The source method name which is used in logRecord for logging purpose has to be set via this method.
Syntax:
public void setSourceMethodName(String sourceMethodName)
Parameters: This method accepts sourceMethodName as a parameter which is the source method name. It can be null also.
Return: This method returns nothing.
Below programs illustrate setSourceMethodName() method:
Program 1:
// Java program to illustrate // setSourceMethodName() 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.SEVERE, "Hello Logger"); // set source method logRecord .setSourceMethodName( "MyFirstSourceMethod"); // print the method name System.out.println( "Source method Name = " + logRecord.getSourceMethodName()); } } |
Source method Name = MyFirstSourceMethod
Program 2:
// Java program to illustrate // setSourceMethodName() method import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.*; public class GFG { public static void main(String[] args) { // Create LogRecord object LogRecord logRecord = new LogRecord(Level.INFO, "GFG Logger"); // set a method from ArrayList class // as source method logRecord.setSourceMethodName( ArrayList .class .getMethods()[0] .getName()); // print the method name System.out.println( "Source method Name = " + logRecord.getSourceMethodName()); // now set null as method name logRecord.setSourceMethodName(null); // print the method name System.out.println( "Now new Source method Name = " + logRecord.getSourceMethodName()); } } |
Source method Name = add Now new Source method Name = null
Recommended Posts:
- LogRecord getInstant() method in Java with Examples
- LogRecord getSourceMethodName() method in Java with Examples
- LogRecord setSequenceNumber() method in Java with Examples
- LogRecord setSourceClassName() method in Java with Examples
- LogRecord getThreadID() method in Java with Examples
- LogRecord getResourceBundle() method in Java with Examples
- LogRecord getMillis() method in Java with Examples
- LogRecord getResourceBundleName() method in Java with Examples
- LogRecord getThrown() method in Java with Examples
- LogRecord setInstant() method in Java with Examples
- LogRecord getSourceClassName() method in Java with Examples
- LogRecord getParameters() method in Java with Examples
- LogRecord getSequenceNumber() method in Java with Examples
- LogRecord setThreadID() method in Java with Examples
- LogRecord setLoggerName() method in Java with Examples
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.



