Open In App

Logger getGlobal() Method in Java with Examples

Last Updated : 22 Mar, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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:




// Java program to demonstrate
// Logger.getGlobal() method
  
import java.util.logging.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
        // Create a logger using getGLobal()
        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:




// Java program to demonstrate
// Logger.getGlobal() method
  
import java.util.logging.*;
  
public class GFG {
  
    // Create a logger using getGLobal()
    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
Previous
Next
Share your thoughts in the comments

Similar Reads