The setLoggerName() method of java.util.logging.LogRecord is used to set the logger name of source.This method returns source logger name if present else returns null.
Syntax:
public void setLoggerName(String name)
Parameters: This method accepts the Source Logger name as a string which can be null also.
Return: This method returns nothing.
Below programs illustrate setLoggerName() method:
Program 1:
// Java program to illustrate setLoggerName() 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" ); // set String class string value as Logger Name logRecord.setLoggerName(String. class .toString()); // print result System.out.println( "Logger Name = " + logRecord.getLoggerName()); } } |
Logger Name = class java.lang.String
Program 2:
// Java program to illustrate setLoggerName() 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" ); // set null as Logger Name logRecord.setLoggerName( null ); // print result System.out.println( "Logger Name = " + logRecord.getLoggerName()); } } |
Logger Name = null
References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/LogRecord.html#setLoggerName(java.lang.String)