Class Log4j2LogBackend

java.lang.Object
org.apache.juneau.rest.server.management.logging.Log4j2LogBackend
All Implemented Interfaces:
LogBackend

public class Log4j2LogBackend extends Object implements 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:

@Bean public LoggersSettings loggersSettings() { return LoggersSettings.create().enableWrite().backend(new Log4j2LogBackend()).build(); }

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 Details

    • Log4j2LogBackend

      Constructor using the current Log4j2 LoggerContext.
    • Log4j2LogBackend

      public Log4j2LogBackend(org.apache.logging.log4j.core.LoggerContext context)
      Constructor with an explicit LoggerContext (for tests / multi-context setups).
      Parameters:
      context - The Log4j2 logger context. Must not be null.
  • Method Details

    • getLevels

      Description copied from interface: LogBackend
      Returns a snapshot of all known loggers and their configured levels.
      Specified by:
      getLevels in interface LogBackend
      Returns:
      A sorted map of logger name → configured level name (empty string = inherited from an ancestor). The root logger is keyed "ROOT". Never null.
    • getLevel

      public String getLevel(String name)
      Description copied from interface: LogBackend
      Returns the configured level of a single logger.
      Specified by:
      getLevel in interface LogBackend
      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

      public void setLevel(String name, String level)
      Description copied from interface: LogBackend
      Sets (or clears) the level of a single logger at runtime (process-lifetime-only).
      Specified by:
      setLevel in interface LogBackend
      Parameters:
      name - The logger name ("ROOT" or empty for the root logger).
      level - The backend-native level name, or null/blank to clear the logger's own level so it inherits from its ancestor.