Java中的 LogRecord setSequenceNumber() 方法及示例
Java.util.logging.LogRecord的setSequenceNumber()方法用于将序列号设置为 LogRecord 以进行日志记录。
句法:
public void setSequenceNumber(long seq)
参数:此方法接受seq作为 long 类型的参数,即我们要设置的序列号。
Return :此方法不返回任何内容。
下面的程序说明了 setSequenceNumber() 方法:
方案一:
// Java program to illustrate
// setSequenceNumber() 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 sequence number
logRecord.setSequenceNumber(41545412);
// print the sequence number
System.out.println(
"Sequence Number = "
+ logRecord.getSequenceNumber());
}
}
输出:
Sequence Number = 41545412
方案二:
// Java program to illustrate
// setSequenceNumber() method
import java.util.logging.Level;
import java.util.logging.LogRecord;
public class Main {
public static void main(String[] args)
{
// Create LogRecord object
LogRecord logRecord
= new LogRecord(Level.INFO,
"GFG Logger");
// set sequence number
logRecord.setSequenceNumber(96236641);
// print the sequence number
System.out.println(
"Sequence Number = "
+ logRecord.getSequenceNumber());
}
输出:
Sequence Number = 96236641
参考: https: Java/util/logging/LogRecord.html#setSequenceNumber(long)