Configuring Logging
You can use the log4j2.xml file to configure logging settings of the Java application, such as name of the log files, their location, and the format of log records.
The log4j2.xml file should be placed at the class path of your application. This is stored in UTF-8 format.
For more details the log4j2.xml file, visit https://logging.apache.org/log4j/2.x/manual/configuration.html#XML.
The following code shows the sample content of the log4j2.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<!-- Rolling File Appender -->
<RollingFile name="RollingFile">
<!-- Name and location of log file -->
<FileName>C:/log/java_unified.log</FileName>
<FilePattern>C:/log/java_unified.%d{yyyy-MM-dd}-%i.log</FilePattern>
<!-- Format of the log file. RequestID represents the unique identifier of the API call. -->
<PatternLayout pattern="%d | 5.0 | java_unified_app | %X{RequestID}| %p | %C.%M:%L - %m%n" />
<Policies>
<TimeBasedTriggeringPolicy/>
<!-- Maximum log file size -->
<SizeBasedTriggeringPolicy size="1 MB"/>
</Policies>
<!-- Maximum number of log files -->
<DefaultRolloverStrategy max="10"/>
</RollingFile>
</Appenders>
<Loggers>
<!-- Logging level -->
<Root level="INFO">
<AppenderRef ref="RollingFile" />
</Root>
</Loggers>
</Configuration>