How to format a log message
Every <RollingFile> element in file log4j2 contains a <PatternLayout> element that defines how to format the text of the logging information in each appender logging file. Apache utility class PatternLayout, a standard part of the Apache log4j-2 distribution, provides the means of handling string patterns.
In the base configuration, each appender uses the default
file.defaultPattern
property to format the logging messages. The default pattern looks similar to the
following code.%-10.10X{server} %-8.24X{userID} %d{yyyy-MM-dd HH:mm:ss,SSS} %p %notEmpty{<%marker>} %m %n
You can, of course, modify the default pattern to
meet your business needs. If you modify the default pattern, you change
the text formatting in all log files globally, if not modified elsewhere.
To modify the text formatting for an individual log category, modify
the <PatternLayout>
element associated with the appender for that logging category.
For more information on conversion patterns, refer to the following Apache documentation:
See also
