Logger getGlobal() Method in Java with Examples
Last Updated :
22 Mar, 2019
getGlobal() method of a Logger class is used to get global logger object with the name Logger.GLOBAL_LOGGER_NAME.The “global” Logger object is helpful for developers who are making casual use of the Logging package. For making serious use of the logging package developers have to create and use their own Logger objects, with appropriate names, so that logging can be controlled on a suitable per-Logger granularity.
At the time of logging in an application, more granular loggers are defined, usually per Java packages or classes. If you do not want to define longer per Java packages or classes, you can use this global logger, which will handle all logging statements, no matter the library, package or class they are contained in.
Syntax:
public static final Logger getGlobal()
Parameters: This method accepts nothing.
Return value: This method return global logger object.
Below programs illustrate the getGlobal() method:
Program 1:
import java.util.logging.*;
public class GFG {
public static void main(String[] args)
{
Logger logger = Logger.getGlobal();
logger.info( "THIS IS MESSAGE ONE" );
logger.info( "THIS IS MESSAGE TWO" );
}
}
|
Output:
The output printed on eclipse IDE shown below-
Program 2:
import java.util.logging.*;
public class GFG {
static Logger logger = Logger.getGlobal();
public static void main(String[] args)
{
logger.info( "THIS IS MESSAGE ONE" );
method1();
method2();
}
public static void method1()
{
logger.info( "THIS IS MESSAGE TWO" );
}
public static void method2()
{
logger.info( "THIS IS MESSAGE THREE" );
}
}
|
Output:
The output printed on eclipse IDE shown below-
Reference: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#getGlobal()
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...