In this section we will see how to customize the XML file so that we can log desired logs we need into the file or the console.
By default, if the log4j.xml file is not available then error is logged in the console of your project. To create a log4j.xml first create a directory in project's root directory. Inside the directory create a file named log4j.xml.
Visit the below link and to copy and paste the content of log4j.xml. We will see the explanation on the content of this file in the short moment,
https://logging.apache.org/log4j/2.x/manual/configuration.html
For conveniences, I will paste the content of the Log4j.xml below,
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> </Console>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
Once copied and pasted then save the file. We will see how to tweak this file,
1. Log Level
ALL
All levels including custom levels.
DEBUG
Designates fine-grained informational events that are most useful to debug an application.
INFO
Designates informational messages that highlight the progress of the application at coarse-grained level.
WARN
Designates potentially harmful situations.
ERROR
Designates error events that might still allow the application to continue running.
FATAL
Designates very severe error events that will presumably lead the application to abort.
OFF
The highest possible rank and is intended to turn off logging.
TRACE
Designates finer-grained informational events than the DEBUG.
2. Pattern
I
3. Output Mode
I