The LoggingMXBean
is an interface in the java.lang.management
package that allows monitoring and managing loggers in a Java application at runtime via JMX (Java Management Extensions).
It provides a way to dynamically inspect and change logging configurations (like log levels) without restarting the application.
Commonly Used Methods

Simple Program
import java.lang.management.ManagementFactory; import java.util.List; import java.util.logging.Logger; import java.util.logging.Level; import java.util.logging.LogManager; import java.util.logging.LoggingMXBean; public class LoggingMXBeanSimple { public static void main(String[] args) { Logger logger = Logger.getLogger("my.logger"); logger.setLevel(Level.WARNING); LoggingMXBean mxBean = ManagementFactory.getPlatformMXBean(LoggingMXBean.class); System.out.println("Logger Names:"); List<String> loggers = mxBean.getLoggerNames(); for (String name : loggers) { if (name.equals("my.logger")) { System.out.println("Logger: " + name); System.out.println("Level: " + mxBean.getLoggerLevel(name)); System.out.println("Parent: " + mxBean.getParentLoggerName(name)); } } } }
Real-Time Log Level Management in a Banking System
Problem Statement
LotusJavaPrince and Mahesh are building a banking backend that logs customer activities. During high load, they want to reduce logging verbosity to avoid IO overhead. Instead of restarting the server, they plan to use JMX and LoggingMXBean
to dynamically change log levels using a monitoring tool like JConsole.
Program: Banking Logs with JMX Runtime Control
import java.lang.management.ManagementFactory; import java.util.logging.*; public class BankingActivityLogger { private static final Logger activityLogger = Logger.getLogger("bank.activity"); public static void main(String[] args) throws InterruptedException { activityLogger.setLevel(Level.INFO); activityLogger.setUseParentHandlers(true); System.out.println("Use JConsole to connect and manage logging level dynamically."); System.out.println("Logger Name: bank.activity"); while (true) { activityLogger.finest("DEBUG: Internal loop details"); activityLogger.fine("FINE: Processing routine transaction..."); activityLogger.info("INFO: LotusJavaPrince performed transaction"); activityLogger.warning("WARNING: Mahesh attempted multiple logins"); Thread.sleep(5000); // Simulate periodic logging } } }
How to Use JConsole to Change Log Level
-
Run the
BankingActivityLogger
program. -
Open JConsole (
jconsole
in terminal). -
Connect to the running Java process.
-
Go to MBeans tab →
java.util.logging
→Logging
. -
Use:
getLoggerNames()
to findbank.activity
.getLoggerLevel("bank.activity")
setLoggerLevel("bank.activity", "SEVERE")
to reduce output.
Outcome
Without restarting the app:
-
Set to
FINE
to increase log detail for debugging. -
Set to
WARNING
to suppress info logs during high traffic.
LoggingMXBean
enables dynamic management of loggers using JMX.This is Excellent for production systems where restarting isn’t an option.This Integrates with JConsole, VisualVM, and other JMX clients.Useful for real-time diagnostics, performance tuning, and auditing.