LogManager

The LogManager class in the java.util.logging package is responsible for:

  • Managing the global logging configuration.
  • Creating and maintaining the Logger namespace.
  • Loading configuration files (e.g., logging.properties).
  • Controlling how loggers are initialized and accessed across the application.

It acts as the central manager for all logging resources in a Java program.

Commonly Used Methods

Simple Program: Register and Retrieve Logger Using LogManager

import java.util.logging.*;

public class LogManagerSimpleExample {
    public static void main(String[] args) {
        LogManager logManager = LogManager.getLogManager();

        Logger myLogger = Logger.getLogger("MyCustomLogger");
        myLogger.setLevel(Level.INFO);
        logManager.addLogger(myLogger); // Register logger

        Logger retrievedLogger = logManager.getLogger("MyCustomLogger");
        retrievedLogger.info("This logger was retrieved via LogManager.");
    }
}

Problem Statement:

LotusJavaPrince and Mahesh are developing a secure banking portal. They want a centralized logging configuration to control the behavior of all loggers across the app using a .properties file. They decide to use LogManager to load this configuration dynamically at runtime.

Configuration File: custom_logging.properties

handlers= java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

com.bank.level = FINE
import java.io.FileInputStream;
import java.io.IOException;
import java.util.logging.*;

public class BankingLoggerWithConfig {
    public static void main(String[] args) {
        try {
            LogManager logManager = LogManager.getLogManager();
            FileInputStream configFile = new FileInputStream("custom_logging.properties");

            logManager.readConfiguration(configFile);
            System.out.println("Custom logging configuration loaded.");

            Logger logger = Logger.getLogger("com.bank");

            logger.finest("FINEST log (debug level - won't show if level is higher)");
            logger.fine("FINE log - for internal processing");
            logger.info("INFO log - visible to business users");
            logger.warning("WARNING - something is off!");
            logger.severe("SEVERE - something is broken!");

        } catch (IOException e) {
            System.err.println("Failed to load logging configuration: " + e.getMessage());
        }
    }
}

Output on Console (based on config)

Custom logging configuration loaded.
May 24, 2025 3:00:00 PM BankingLoggerWithConfig main
FINE: FINE log - for internal processing
May 24, 2025 3:00:00 PM BankingLoggerWithConfig main
INFO: INFO log - visible to business users
May 24, 2025 3:00:00 PM BankingLoggerWithConfig main
WARNING: WARNING - something is off!
May 24, 2025 3:00:00 PM BankingLoggerWithConfig main
SEVERE: SEVERE - something is broken!Code language: CSS (css)

LogManager is the heart of Java’s logging system. It controls Logger registration,Logger hierarchy,Configuration loading.Useful for enterprise apps where centralized logging policies are required.

Scroll to Top