Page History
...
Level | Description |
---|---|
OFF | The highest possible rank and is intended to turn off logging. |
FATAL | Severe errors that cause premature termination. Visible in console. |
ERROR | Other runtime errors or unexpected conditions. Visible in console. |
WARN | Use of deprecated APIs, poor use of API, "almost" errors, other runtime situations that are undesirable or unexpected, but not necessarily "wrong". Visible in console. |
INFO | Interesting runtime events (startup/shutdown). Visible in console, so be conservative and keep to a minimum. |
DEBUG | Detailed information on the flow through the system. Written to logs only. |
TRACE | More detailed information. Written to logs only. |
Pattern layout
Log4j2's Pattern Layout is a customizable log message formatter that uses conversion patterns to generate structured log outputs.
Note |
---|
The log message is encoded to address CWE 117 (Improper Output Neutralization for Logs), ensuring user-supplied data is properly sanitized so as to prevent log injection attacks. |
Example PatternLayout
Code Block | ||
---|---|---|
| ||
<PatternLayout pattern="%d %-5p %-50.50c: %encode{%m}{CRLF}%n"/> |
The above pattern matches:
%d
= the date.%-5p
= the priority (p
) left-justified by5
characters.%-50.50c:
= the name of the logger that published the logging event.%encode{%m}{CRLF}%n
= encodes the user message preventing the CRLF characters from the stream.
Appenders
Appenders define where the output is directed. The following appenders are configured by default in log4j2.xml
. They write messages to the console and to various log files.
Appender | Writes to | Notes |
---|---|---|
| Console | Default output for DEBUG messages |
|
| Default output for DEBUG messages. |
|
| Default output for ERROR messages. |
|
| Content publishing. |
|
| Bootstrap process. |
|
| System access. |
|
| See Audit. |
|
| |
| Sends mail. | Disabled by default. |
...