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. |
...
To capture the headers, you can use a browser extension or plugin that displays headers for the currently open page. A plugin's advantage over a Monitoring#Websites Websites is that you can also use it for sites that only exist in your local environment or intranet.
...
- Open Developer Tools.
- Go to Network.
- Reload the page.
- Select the page in the list.
- Go to Headers tab.
Command line tools
...
Java Monitoring and Management Console (JConsole) is a graphical tool that supports JMX monitoring and management on a local or remote machine. It draws graphs for visual representation of performance and resource consumption, which makes it easier to observe changes over time. As a downside, the results are not as easy to export as with Monitoring#Jmxterm Jmxterm.
Starting JConsole
- Start JConsole:
$ jconsole
- Connect to a process:
- Local: Select a Java process running on the local machine. Magnolia running on Tomcat would be listed as
org.apache.catalina.startup.Boostrap start
. - Remote: Type a remote process location as
<hostname>:<port>
orservice:jmx:<protocol>:<sap>
.
- Local: Select a Java process running on the local machine. Magnolia running on Tomcat would be listed as
- Click Connect
...