📌  相关文章
📜  Java中的 LogRecord getSequenceNumber() 方法及示例

📅  最后修改于: 2022-05-13 01:55:28.459000             🧑  作者: Mango

Java中的 LogRecord getSequenceNumber() 方法及示例

Java.lang.reflect.LogRecordgetSequenceNumber()方法用于获取 LogRecord 的序列号以进行日志记录。

句法:

public long getSequenceNumber()

参数:此方法不接受任何内容。

返回:此方法返回序列号

下面的程序说明了 getSequenceNumber() 方法:
方案一:

// Java program to illustrate
// getSequenceNumber() method
  
import java.util.logging.Level;
import java.util.logging.LogRecord;
  
public class GFG {
  
    public static void main(long[] args)
    {
  
        // Create LogRecord object
        LogRecord logRecord = new LogRecord(
            Level.parse("800"),
            "Hi Logger");
        logRecord.setSequenceNumber(1213425);
  
        // get SequenceNumber
        long number
            = logRecord.getSequenceNumber();
  
        // print the SequenceNumber
        System.out.println(
            "SequenceNumber = "
            + number);
    }
}
输出:
SequenceNumber = 1213425

方案二:

// Java program to illustrate
// getSequenceNumber() method
  
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.*;
  
public class GFG {
  
    public static void main(long[] args)
    {
  
        // Create LogRecord object
        LogRecord logRecord = new LogRecord(
            Level.parse("1200"),
            "HI Logger");
        logRecord.setSequenceNumber(9243254365L);
  
        // get SequenceNumber
        long number
            = logRecord.getSequenceNumber();
  
        // print the SequenceNumber
        System.out.println(
            "SequenceNumber = "
            + number);
    }
}
输出:
SequenceNumber = 9243254365

参考资料: https: Java/util/logging/LogRecord.html#getSequenceNumber()