Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: add MGNLCE-363 in hide

...

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.

Hide block

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
languagebash
<PatternLayout pattern="%d %-5p %-50.50c: %encode{%m}{CRLF}%n"/>

The above pattern matches:

  • %d = the date.
  • %-5p = the priority (p) left-justified by 5 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.

...