LogRecord getLoggerName() method in Java with Examples

The getLoggerName() method of java.util.logging.LogRecord is used to get the logger name of source.This method returns source logger name if present else returns null.

Syntax:

public String getLoggerName()

Parameters: This method accepts nothing.



Return: This method returns source logger name if present else returns null.

Below programs illustrate getLoggerName() method:
Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to illustrate getLoggerName() method
  
import java.util.logging.Level;
import java.util.logging.LogRecord;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Create LogRecord object with a logger name
        LogRecord logRecord = new LogRecord(
            Level.parse("800"),
            "Hi Logger");
        logRecord.setLoggerName("StringLogger");
  
        // get Logger Name of LogRecord
        String name = logRecord.getLoggerName();
  
        // print result
        System.out.println("Logger Name = "
                           + name);
    }
}

chevron_right


Output:

Logger Name = StringLogger

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to illustrate getLoggerName() method
  
import java.util.logging.Level;
import java.util.logging.LogRecord;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Create LogRecord object with a logger name
        LogRecord logRecord = new LogRecord(
            Level.parse("400"),
            "GFG Logger");
        logRecord.setLoggerName(String.class.toString());
  
        // get Logger Name of LogRecord
        String name = logRecord.getLoggerName();
  
        // print result
        System.out.println("Logger Name = "
                           + name);
    }
}

chevron_right


Output:

Logger Name = class java.lang.String

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



My Personal Notes arrow_drop_up

I am a Developer I love to code and bring my ideas alive

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.