Skip to content
Related Articles

Related Articles

LogRecord getSourceClassName() method in Java with Examples

View Discussion
Improve Article
Save Article
  • Last Updated : 23 Oct, 2019
View Discussion
Improve Article
Save Article

The getSourceClassName() method of java.lang.reflect.LogRecord is used to get the name of the class that allegedly issued the logging request. The source class name which is used in logRecord for logging purpose.

Syntax:

public String getSourceClassName()

Parameters: This method accepts nothing.

Return: This method returns the source class name.

Below programs illustrate getSourceClassName() method:
Program 1:




// Java program to illustrate
// getSourceClassName() 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.parse("800"),
            "Hi Logger");
        logRecord.setSourceClassName(
            String.class.getName());
  
        // get source class name
        String sourceClass
            = logRecord.getSourceClassName();
  
        // print the class name
        System.out.println(
            "Source class Name = "
            + sourceClass);
    }
}

Output:

Source class Name = java.lang.String

Program 2:




// Java program to illustrate
// getSourceClassName() 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.parse("600"),
            "GFG Logger");
        logRecord.setSourceClassName(
            Object.class.getName());
  
        // get source class name
        String sourceClass
            = logRecord.getSourceClassName();
  
        // print the class name
        System.out.println(
            "Source class Name = "
            + sourceClass);
    }
}

Output:

Source class Name = java.lang.Object

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


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!