LoggingMXBean
Stay organized with collections
Save and categorize content based on your preferences.
The management interface for the logging facility.
There is a single global instance of the LoggingMXBean.
The javax.management.ObjectName ObjectName
that uniquely identifies
the management interface for logging within the MBeanServer
is:
java.util.logging:type=Logging
Public Methods
public
abstract
String
getLoggerLevel
(String loggerName)
Gets the name of the log level associated with the specified logger.
If the specified logger does not exist, null
is returned.
This method first finds the logger of the given name and
then returns the name of the log level by calling:
Logger.getLevel()
.getName()
;
If the Level of the specified logger is null,
which means that this logger's effective level is inherited
from its parent, an empty string will be returned.
Parameters
loggerName |
The name of the Logger to be retrieved. |
Returns
- The name of the log level of the specified logger; or
an empty string if the log level of the specified logger
is null. If the specified logger does not
exist, null is returned.
public
abstract
List<String>
getLoggerNames
()
Returns the list of currently registered logger names. This method
calls LogManager.getLoggerNames()
and returns a list
of the logger names.
Returns
- A list of String each of which is a
currently registered Logger name.
public
abstract
String
getParentLoggerName
(String loggerName)
Returns the name of the parent for the specified logger.
If the specified logger does not exist, null is returned.
If the specified logger is the root Logger in the namespace,
the result will be an empty string.
Parameters
loggerName |
The name of a Logger. |
Returns
- the name of the nearest existing parent logger;
an empty string if the specified logger is the root logger.
If the specified logger does not exist, null
is returned.
public
abstract
void
setLoggerLevel
(String loggerName, String levelName)
Sets the specified logger to the specified new level.
If the levelName is not null, the level
of the specified logger is set to the parsed Level
matching the levelName.
If the levelName is null, the level
of the specified logger is set to null and
the effective level of the logger is inherited from
its nearest ancestor with a specific (non-null) level value.
Parameters
loggerName |
The name of the Logger to be set.
Must be non-null. |
levelName |
The name of the level to set on the specified logger,
or null if setting the level to inherit
from its nearest ancestor. |
Throws
IllegalArgumentException |
if the specified logger
does not exist, or levelName is not a valid level name. |
SecurityException |
if a security manager exists and if
the caller does not have LoggingPermission("control"). |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eLoggingMXBean\u003c/code\u003e provides a management interface for the logging facility with a single global instance.\u003c/p\u003e\n"],["\u003cp\u003eIt allows retrieval of logger levels, names, and parent logger names using methods like \u003ccode\u003egetLoggerLevel\u003c/code\u003e, \u003ccode\u003egetLoggerNames\u003c/code\u003e, and \u003ccode\u003egetParentLoggerName\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003esetLoggerLevel\u003c/code\u003e method enables setting a specific logger's level, including inheriting from its nearest ancestor.\u003c/p\u003e\n"],["\u003cp\u003eIf a logger or level name is invalid, \u003ccode\u003eIllegalArgumentException\u003c/code\u003e is thrown; \u003ccode\u003eSecurityException\u003c/code\u003e is thrown if the caller lacks sufficient permissions.\u003c/p\u003e\n"]]],["The `LoggingMXBean` interface manages logging. Key actions include: retrieving a logger's log level name via `getLoggerLevel`, which returns an empty string if inherited or null if the logger is not found; listing all logger names with `getLoggerNames`; and finding a logger's parent name using `getParentLoggerName`, which returns empty if the logger is the root or null if the logger does not exist. You can also set a logger's level with `setLoggerLevel`.\n"],null,["# LoggingMXBean\n\npublic interface **LoggingMXBean** \nThe management interface for the logging facility.\n\nThere is a single global instance of the LoggingMXBean.\n\nThe `javax.management.ObjectName ObjectName` that uniquely identifies\nthe management interface for logging within the `MBeanServer` is: \n\n ../../../../reference/java/util/logging/LogManager.html#LOGGING_MXBEAN_NAME\n \n\u003cbr /\u003e\n\n### Public Method Summary\n\n|---------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [String](../../../../reference/java/lang/String.html) | [getLoggerLevel](../../../../reference/java/util/logging/LoggingMXBean.html#getLoggerLevel(java.lang.String))([String](../../../../reference/java/lang/String.html) loggerName) Gets the name of the log level associated with the specified logger. |\n| abstract [List](../../../../reference/java/util/List.html)\\\u003c[String](../../../../reference/java/lang/String.html)\\\u003e | [getLoggerNames](../../../../reference/java/util/logging/LoggingMXBean.html#getLoggerNames())() Returns the list of currently registered logger names. |\n| abstract [String](../../../../reference/java/lang/String.html) | [getParentLoggerName](../../../../reference/java/util/logging/LoggingMXBean.html#getParentLoggerName(java.lang.String))([String](../../../../reference/java/lang/String.html) loggerName) Returns the name of the parent for the specified logger. |\n| abstract void | [setLoggerLevel](../../../../reference/java/util/logging/LoggingMXBean.html#setLoggerLevel(java.lang.String,%20java.lang.String))([String](../../../../reference/java/lang/String.html) loggerName, [String](../../../../reference/java/lang/String.html) levelName) Sets the specified logger to the specified new level. |\n\nPublic Methods\n--------------\n\n#### public abstract [String](../../../../reference/java/lang/String.html)\n**getLoggerLevel**\n([String](../../../../reference/java/lang/String.html) loggerName)\n\nGets the name of the log level associated with the specified logger.\nIf the specified logger does not exist, null\nis returned.\nThis method first finds the logger of the given name and\nthen returns the name of the log level by calling:\n\u003e [Logger.getLevel()](../../../../reference/java/util/logging/Logger.html#getLevel()).[getName()](../../../../reference/java/util/logging/Level.html#getName());\n\n\nIf the Level of the specified logger is null,\nwhich means that this logger's effective level is inherited\nfrom its parent, an empty string will be returned. \n\n##### Parameters\n\n| loggerName | The name of the Logger to be retrieved. |\n|------------|-----------------------------------------|\n\n##### Returns\n\n- The name of the log level of the specified logger; or an empty string if the log level of the specified logger is null. If the specified logger does not exist, null is returned. \n\n##### See Also\n\n- [Logger.getLevel()](../../../../reference/java/util/logging/Logger.html#getLevel()) \n\n#### public abstract [List](../../../../reference/java/util/List.html)\\\u003c[String](../../../../reference/java/lang/String.html)\\\u003e\n**getLoggerNames**\n()\n\nReturns the list of currently registered logger names. This method\ncalls [LogManager.getLoggerNames()](../../../../reference/java/util/logging/LogManager.html#getLoggerNames()) and returns a list\nof the logger names. \n\n##### Returns\n\n- A list of String each of which is a currently registered Logger name. \n\n#### public abstract [String](../../../../reference/java/lang/String.html)\n**getParentLoggerName**\n([String](../../../../reference/java/lang/String.html) loggerName)\n\nReturns the name of the parent for the specified logger.\nIf the specified logger does not exist, null is returned.\nIf the specified logger is the root Logger in the namespace,\nthe result will be an empty string. \n\n##### Parameters\n\n| loggerName | The name of a Logger. |\n|------------|-----------------------|\n\n##### Returns\n\n- the name of the nearest existing parent logger; an empty string if the specified logger is the root logger. If the specified logger does not exist, null is returned. \n\n#### public abstract void\n**setLoggerLevel**\n([String](../../../../reference/java/lang/String.html) loggerName, [String](../../../../reference/java/lang/String.html) levelName)\n\nSets the specified logger to the specified new level.\nIf the levelName is not null, the level\nof the specified logger is set to the parsed Level\nmatching the levelName.\nIf the levelName is null, the level\nof the specified logger is set to null and\nthe effective level of the logger is inherited from\nits nearest ancestor with a specific (non-null) level value. \n\n##### Parameters\n\n| loggerName | The name of the Logger to be set. Must be non-null. |\n| levelName | The name of the level to set on the specified logger, or null if setting the level to inherit from its nearest ancestor. |\n|------------|--------------------------------------------------------------------------------------------------------------------------|\n\n##### Throws\n\n| [IllegalArgumentException](../../../../reference/java/lang/IllegalArgumentException.html) | if the specified logger does not exist, or levelName is not a valid level name. |\n| [SecurityException](../../../../reference/java/lang/SecurityException.html) | if a security manager exists and if the caller does not have LoggingPermission(\"control\"). |\n|-------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|\n\n##### See Also\n\n- [Logger.setLevel(Level)](../../../../reference/java/util/logging/Logger.html#setLevel(java.util.logging.Level))"]]