Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

LogManager addLogger() method in Java with Examples

  • Last Updated : 29 Oct, 2019

The addLogger() method of java.util.logging.LogManager is used to insert the specified Logger in this LogManager instance. This Logger must be a named Logger. This method will add this Logger in this LogManager if it does not exist already. If it exists already, then this method returns false.


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.

public boolean addLogger(Logger logger)

Parameters: This method accepts a parameter logger which is the name of the Logger to be inserted in this LogManager instance, if it does not exist already.

Return Value: This method returns a boolean value false, if this Logger does exist already. Else this method does not return anything.

Exceptions: This method throws NullPointerException if the logger to be added is null.

Below programs illustrate addLogger() method:

// Java program to illustrate
// LogManager addLogger() method
import java.util.logging.*;
import java.util.*;
public class GFG {
    public static void main(String[] args)
        // Create LogManager object
        LogManager logManager
            = LogManager.getLogManager();
        Enumeration<String> listOfNames
            = logManager.getLoggerNames();
        System.out.println("Earlier List of Logger Names: ");
        while (listOfNames.hasMoreElements())
        String LoggerName = "GFG";
        Logger logger
            = Logger.getLogger(LoggerName);
        System.out.println("Adding Logger: " + LoggerName);
        listOfNames = logManager.getLoggerNames();
        System.out.println("\nUpdated List of Logger Names: ");
        while (listOfNames.hasMoreElements())
Earlier List of Logger Names: 

Adding Logger: GFG

Updated List of Logger Names: 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!