Skip to content

Log4j2 Root Logger Configuration

The Root Logger serves as the default logger in Log4j2, handling log events for classes that do not have a specific logger configuration explicitly defined.^[600-developer-java-3-party-java-log4j2.md] It is configured within the <Loggers> section of the XML configuration file.

Syntax

In the XML configuration, the Root Logger is defined using the <Root> tag.^[600-developer-java-3-party-java-log4j2.md] It must include a level attribute to define the logging threshold (e.g., "all", "debug", "info") and one or more <AppenderRef> elements to direct log output to specific destinations like the console or files.^[600-developer-java-3-party-java-log4j2.md]

<Root level="all">
    <AppenderRef ref="Console"/>
</Root>

Relationship with Other Loggers

When specific loggers are defined in the configuration, they typically require the additivity attribute to be set to false.^[600-developer-java-3-party-java-log4j2.md] If additivity is false, the log events for that specific logger are handled only by the appenders referenced in that logger's definition and are not passed up to the Root Logger.^[600-developer-java-3-party-java-log4j2.md] This allows for granular separation of log outputs (e.g., routing specific components to dedicated files) without cluttering the main log or console output defined by the Root Logger.

  • [[Loggers]]
  • [[XML configuration]]
  • [[Appenders]]

Sources

^[600-developer-java-3-party-java-log4j2.md]