XML format
Log4j 2 config
How a Java application decides what to log and where, in a file whose element names are plugin names rather than a fixed vocabulary.
log4j2.xml configures appenders, layouts and loggers for one of the most widely deployed logging frameworks in Java. It has no schema in the ordinary sense: element names resolve to plugins by name, so <RollingFile> works because a plugin registered itself under that name, and a typo produces a component that silently does not exist rather than a validation error.
Logger configuration is hierarchical by dotted name, and additivity is the setting that catches people: a logger both handles an event and passes it to its parent unless told otherwise, which is how one message ends up in three files.
- Element names are plugin names and are matched case-insensitively. A misspelling is not an error — the component is simply absent.
- Set additivity="false" on a logger with its own appender, or events also go to the root logger's appenders.
- status on the root element controls Log4j's own internal logging, and is the only way to see why a configuration did not load.
- Property substitution uses ${...} with a prefix (${env:…}, ${sys:…}); an unresolved lookup is left as the literal text.
- The file is watched only if monitorInterval is set, and the minimum effective interval is measured in seconds.
- Root element
<Configuration>- Media type
application/xml- Extensions
.xml- Namespaces
- None — unqualified elements
- XMLDir label
- —
Specification: Log4j 2 configuration
A minimal valid document
Every example on this site is checked against the same parser the workspace uses, so what you see below is known to be well-formed.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="30">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{ISO8601} %-5level %logger{36} - %msg%n"/>
</Console>
<RollingFile name="File" fileName="logs/app.log"
filePattern="logs/app-%d{yyyy-MM-dd}.log.gz">
<JsonTemplateLayout/>
<TimeBasedTriggeringPolicy/>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="com.example.audit" level="info" additivity="false">
<AppenderRef ref="File"/>
</Logger>
<Root level="warn">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>Other formats
- XML sitemap
- Sitemap index
- RSS 2.0
- Atom 1.0
- SOAP envelope
- XML Schema (XSD)
- WSDL
- XSLT stylesheet
- SVG
- OPML
- RDF/XML
- GPX
- KML
- XLIFF
- UBL Invoice
- JUnit XML
- Maven POM
- SAML 2.0
- Property list
- DocBook 5
- JATS article
- MusicXML 4.0
- MathML
- XSL-FO
- OOXML document
- Android manifest
- Android strings
- MSBuild project
- JaCoCo report
- Checkstyle report
- EPUB package
- XMP metadata
- TEI document
- ISO 20022 pain.001
- HL7 CDA
- TTML captions
- OpenStreetMap XML
Get started
Bring order to the XML your team can't afford to ignore.
Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.