java.util.logging.LogRecord的setSourceMethodName()方法用于设置据称发出日志请求的方法的名称。必须通过此方法设置logRecord中用于记录目的的源方法名称。
用法:
public void setSourceMethodName(String sourceMethodName)
参数:此方法接受sourceMethodName作为参数,这是源方法的名称。也可以为null。
返回:此方法不返回任何内容。
以下示例程序旨在说明setSourceMethodName()方法:
示例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
示例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
相关用法
- Java LogRecord getSourceMethodName()用法及代码示例
- Java LogRecord setSequenceNumber()用法及代码示例
- Java LogRecord getInstant()用法及代码示例
- Java LogRecord getSourceClassName()用法及代码示例
- Java LogRecord getParameters()用法及代码示例
- Java LogRecord getSequenceNumber()用法及代码示例
- Java LogRecord getThreadID()用法及代码示例
- Java LogRecord getMessage()用法及代码示例
- Java LogRecord getLoggerName()用法及代码示例
- Java LogRecord setResourceBundleName()用法及代码示例
- Java LogRecord setResourceBundle()用法及代码示例
- Java LogRecord setParameters()用法及代码示例
- Java LogRecord setMillis()用法及代码示例
- Java LogRecord setLoggerName()用法及代码示例
- Java LogRecord setSourceClassName()用法及代码示例
注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 LogRecord setSourceMethodName() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。