Default logging categories
To ensure that all logging categories have
a default logging level, file log4j2.xml
defines logging levels for the main default loggers, Console and DailyLogFile, using the following
<Root> element definition.
<Configuration>
...
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
<AppenderRef ref="DailyLogFile" />
...
</Configuration>
name or additivity attribute. It does
have a level attribute.Child loggers inherit their logging level from their parent logger, unless otherwise changed. In this way, you can achieve a fine-grained set of logging levels by logging category. The following code sample illustrates this concept.
<Logger name="Server.Archiving" level="info">
<AppenderRef ref="ArchiveLog"/>
</Logger>
<Logger name="Server.Archiving.Success" level="info">
<AppenderRef ref="ArchiveLog"/>
</Logger>
<Logger name="Server.Archiving.Graph" level="debug">
<AppenderRef ref="ArchiveLog"/>
</Logger>
<Logger name="Server.Archiving.Graph" level="warn">
<AppenderRef ref="Console"/>
</Logger>
<Logger name="Server.Archiving.DocumentUpgrade" level="trace">
<AppenderRef ref="ArchiveLog"/>
</Logger>
In the example, Server.Archiving
is the parent logger, which the logger sets to the info logging level. Child logger
Server.Archiving.Sucess
explicitly sets this same logging level.
However, notice that there are two loggers for Server.Archiving.Graph:
- One logger sets the logging level
to
debugfor logging messages written to the archive log (ArchiveLog). - The other logger sets
the logging level to
warnfor logging messages written to the application console (Console).
The last logger, Server.Archiving.DocumentUpgrade,
sets the logging level to trace
and writes its logging messages to the archive log.
See also
- Root logging appender definitions
- For a information on logging levels and inheritance, refer to the Apache
log4j2documentation:
