log4j2####
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<Configuration status="off">
<!--Appender settings used for logging-->
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout>
<pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}], %-5p, %t, %c, %m%n</pattern>
</PatternLayout>
</Console>
<RollingFile name="FILE" fileName="./log/appLog.log" filePattern="appLog-%d{yyyy-MM-dd}-%i.log">
<TimeBasedTriggeringPolicy />
<!-- <SizeBasedTriggeringPolicy size="100MB" /> -->
<DefaultRolloverStrategy max="3"/>
</RollingFile>
</Appenders>
<!--Setting the logger to use for output-->
<Loggers>
<Root level="DEBUG">
<AppenderRef ref="STDOUT" level="INFO"/>
<!-- <AppenderRef ref="FILE" /> -->
</Root>
</Loggers>
</Configuration>
Log level
DEBUG < INFO < WARN < ERROR < FATAL
Any JAVA.java
logger.info("The entered parameter is "{}"is.", name);
//Below logger test
logger.debug("logger.debug");
logger.info("logger.info");
logger.warn("logger.warn");
logger.error("logger.error");
logger.fatal("logger.fatal");
result
For INFO
[2018-11-10 13:16:40.479], INFO , http-nio-8080-exec-2, sample.HelloWorldAction,The parameter entered is "test".
[2018-11-10 13:16:40.481], INFO , http-nio-8080-exec-2, sample.HelloWorldAction, logger.info
[2018-11-10 13:16:40.481], WARN , http-nio-8080-exec-2, sample.HelloWorldAction, logger.warn
[2018-11-10 13:16:40.481], ERROR, http-nio-8080-exec-2, sample.HelloWorldAction, logger.error
[2018-11-10 13:16:40.481], FATAL, http-nio-8080-exec-2, sample.HelloWorldAction, logger.fatal
In case of ERROR
[2018-11-10 13:19:16.131], ERROR, http-nio-8080-exec-9, sample.HelloWorldAction, logger.error
[2018-11-10 13:19:16.147], FATAL, http-nio-8080-exec-9, sample.HelloWorldAction, logger.fatal