Sunday, November 17, 2024
Google search engine
HomeLanguagesJavaLogRecord setSequenceNumber() method in Java with Examples

LogRecord setSequenceNumber() method in Java with Examples

The setSequenceNumber() method of java.util.logging.LogRecord is used to set the sequence number to LogRecord for logging purpose.

Syntax:

public void setSequenceNumber(long seq)

Parameters: This method accepts seq as a parameter of long type which is the sequence number we want to set.

Return: This method returns nothing.

Below programs illustrate setSequenceNumber() method:
Program 1:




// 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());
    }
}


Output:

Sequence Number = 41545412

Program 2:




// 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());
    }


Output:

Sequence Number = 96236641

References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/LogRecord.html#setSequenceNumber(long)

RELATED ARTICLES

Most Popular

Recent Comments