Skip to content
Related Articles

Related Articles

Improve Article

Logger getGlobal() Method in Java with Examples

  • Last Updated : 22 Mar, 2019
Geek Week

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()

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :