Logger getName() Method in Java with Examples
Last Updated :
26 Mar, 2019
getName() method of a Logger class used to get the name of logger. Many times you have to check the logger name so we can use this method to get the logger name.
Syntax:
public String getName()
Parameters: This method accepts nothing.
Return value: This method return logger name and it will be null for anonymous Loggers.
Below programs illustrate the getName() method:
Program 1:
import java.util.logging.*;
public class GFG {
static Logger logger1
= Logger.getGlobal();
static Logger logger2
= Logger.getLogger( "com.gfg" );
public static void main(String[] args)
{
System.out.println( "logger1 name = "
+ logger1.getName());
System.out.println( "logger2 name = "
+ logger2.getName());
}
}
|
Output:
logger1 name = global
logger2 name = com.gfg
Program 2:
import java.util.logging.*;
public class GFG {
static Logger logger
= Logger.getLogger( "com.gfg.logger." );
public static void main(String[] args)
{
System.out.println( "logger name = "
+ logger.getName());
}
}
|
Output:
logger name = com.gfg.logger.
Reference: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#getName()
Share your thoughts in the comments
Please Login to comment...