Wednesday, July 3, 2024
HomeLanguagesJavaLogRecord getLoggerName() method in Java with Examples

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:




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


Output:

Logger Name = StringLogger

Program 2:




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


Output:

Logger Name = class java.lang.String

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

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments