Logger getGlobal() Method in Java with Examples

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:
The output printed on eclipse IDE shown below-

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:
The output printed on eclipse IDE shown below-

Reference: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#getGlobal()



My Personal Notes arrow_drop_up

I am a Developer I love to code and bring my ideas alive

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.