Class Log4j2LogBackend
- All Implemented Interfaces:
LogBackend
LogBackend adapter for Apache Log4j 2,
for use behind the /loggers management endpoint.
Drives the concrete Log4j2 LoggerContext / Configuration — not SLF4J the facade
(an SLF4J→Log4j2 binding still routes here because the emitting backend is Log4j2). Register it explicitly:
Level mapping
Levels are Log4j2 standard level names ("TRACE", "DEBUG", "INFO", "WARN",
"ERROR", "FATAL", "OFF", "ALL"). Reads report each LoggerConfig's
configured level. Sets are process-lifetime-only (Configurator.setLevel(String, Level)); the
root logger is addressed as "ROOT".
Log4j2 has no "inherited / no own level" sentinel the way JUL/Logback do — every LoggerConfig in
the configuration carries a concrete level — so reads return a level name (never the empty-string
"inherited" marker) for configured loggers, and null for a name that has no LoggerConfig.
- Since:
- 10.0.0
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor using the current Log4j2LoggerContext.Log4j2LogBackend(org.apache.logging.log4j.core.LoggerContext context) Constructor with an explicitLoggerContext(for tests / multi-context setups). -
Method Summary
Modifier and TypeMethodDescriptionReturns the configured level of a single logger.Returns a snapshot of all known loggers and their configured levels.voidSets (or clears) the level of a single logger at runtime (process-lifetime-only).
-
Constructor Details
-
Log4j2LogBackend
public Log4j2LogBackend()Constructor using the current Log4j2LoggerContext. -
Log4j2LogBackend
Constructor with an explicitLoggerContext(for tests / multi-context setups).- Parameters:
context- The Log4j2 logger context. Must not benull .
-
-
Method Details
-
getLevels
Description copied from interface:LogBackendReturns a snapshot of all known loggers and their configured levels.- Specified by:
getLevelsin interfaceLogBackend- Returns:
- A sorted map of logger name → configured level name (empty string = inherited from an
ancestor). The root logger is keyed
"ROOT". Nevernull .
-
getLevel
Description copied from interface:LogBackendReturns the configured level of a single logger.- Specified by:
getLevelin interfaceLogBackend- Parameters:
name- The logger name ("ROOT"or empty for the root logger).- Returns:
- The configured level name, the empty string if the level is inherited, or
null if no such logger is currently registered.
-
setLevel
Description copied from interface:LogBackendSets (or clears) the level of a single logger at runtime (process-lifetime-only).- Specified by:
setLevelin interfaceLogBackend- Parameters:
name- The logger name ("ROOT"or empty for the root logger).level- The backend-native level name, ornull /blank to clear the logger's own level so it inherits from its ancestor.
-