1. Maven introduces the package and excludes the default log
1
2org.springframework.boot
3spring-boot-starter
4
5
6org.springframework.boot
7spring-boot-starter-logging
8
9
10
11
12org.springframework.boot
13spring-boot-starter-log4j2
14
2, add a configuration file, put it under resources, start the project, The log can be recorded, and the modification of the related configuration can be operated in the configuration file.
1 xml version="1.0" encoding="UTF-8"?>
2 < configuration>
3 < appenders>
4
5 < console name="Console" target="SYSTEM_OUT">
6 < PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %class %L %M-%msg%n"/>
7 console>
8
9
10 < RollingFile name="all" fileName="logs/allOut.log"
11 filePattern ="logs/$${date:yyyy-MM-dd}/allOut-%d{yyyy-MM-dd}-%i.log">
12 < Filters>
13 < ThresholdFilter level="all" onMatch="ACCEPT" onMismatch="DENY"/>
14 Filters>
15
16 < PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %class{36} %L %M-%msg%n"/>
17 < Policies>
18
19 < SizeBasedTriggeringPolicy size="2 MB"/>
20 Policies>
21
22 < DefaultRolloverStrategy max="50"/>
23 RollingFile>
24
25 < RollingFile name="err" fileName="logs/err.log"
26 filePattern ="logs/$${date:yyyy-MM-dd}/err-%d{yyyy-MM-dd}-%i.log">
27 < Filters>
28 < ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
29 Filters>
30
31 < PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %class{36} %L %M-%msg%xEx%n"/>
32 < Policies>
33
34 < SizeBasedTriggeringPolicy size="10MB"/>
35 Policies>
36
37 < DefaultRolloverStrategy max="50"/>
38 RollingFile>
39 appenders>
40
41 < loggers>
42
43 < logger name="org.springframework" level="error"> logger>
44
45 < root level="debug">
46 < appender-ref ref="Console"/>
47 < appender-ref ref="all"/>
48 < appender-ref ref="err"/>
49 root>
50 loggers>
51
52 configuration>
Configuration file
< /p>
1
2org.springframework.boot
3spring-boot-starter
4
5
6org.springframework.boot
7spring-boot-starter-logging
8
9
10
11
12org.springframework.boot
13spring-boot-starter-log4j2
14
1 < span style="color: #0000ff;">xml version="1.0" encoding="UTF-8"?>
2 < configuration>
3 < appenders>
4
5 < console name="Console" target="SYSTEM_OUT">
6 < PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %class %L %M-%msg%n"/>
7 console>
8
9
10 < RollingFile name="all" fileName="logs/allOut.log"
11 filePattern ="logs/$${date:yyyy-MM-dd}/allOut-%d{yyyy-MM-dd}-%i.log">
12 < Filters>
13 < ThresholdFilter level="all" onMatch="ACCEPT" onMismatch="DENY"/>
14 Filters>
15
16 < PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %class{36} %L %M-%msg%n"/>
17 < Policies>
18
19 < SizeBasedTriggeringPolicy size="2 MB"/>
20 Policies>
21
22 < DefaultRolloverStrategy max="50"/>
23 RollingFile>
24
25 < RollingFile name="err" fileName="logs/err.log"
26 filePattern ="logs/$${date:yyyy-MM-dd}/err-%d{yyyy-MM-dd}-%i.log">
27 < Filters>
28 < ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
29 Filters>
30
31 < PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %class{36} %L %M-%msg%xEx%n"/>
32 < Policies>
33
34 < SizeBasedTriggeringPolicy size="10MB"/>
35 Policies>
36
37 < DefaultRolloverStrategy max="50"/>
38 RollingFile>
39 appenders>
40
41 < loggers>
42
43 < logger name="org.springframework" level="error"> logger>
44
45 < root level="debug">
46 < appender-ref ref="Console"/>
47 < appender-ref ref="all"/>
48 < appender-ref ref="err"/>
49 root>
50 loggers>
51
52 configuration>
Configuration file
< p>
1 xml version="1.0" encoding="UTF-8"?>
2 < configuration>
3 < appenders>
4
5 < console name="Console" target="SYSTEM_OUT">
6 < PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %class %L %M-%msg%n"/>
7 console>
8
9
10 < RollingFile name="all" fileName="logs/allOut.log"
11 filePattern ="logs/$${date:yyyy-MM-dd}/allOut-%d{yyyy-MM-dd}-%i.log">
12 < Filters>
13 < ThresholdFilter level="all" onMatch="ACCEPT" onMismatch="DENY"/>
14 Filters>
15
16 < PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %class{36} %L %M-%msg%n"/>
17 <Policies>
18
19 <SizeBasedTriggeringPolicy size="2 MB"/>
20 Policies>
21
22 <DefaultRolloverStrategy max="50"/>
23 RollingFile>
24
25 <RollingFile name="err" fileName="logs/err.log"
26 filePattern="logs/$${date:yyyy-MM-dd}/err-%d{yyyy-MM-dd}-%i.log">
27 <Filters>
28 <ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
29 Filters>
30
31 <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %class{36} %L %M - %msg%xEx%n"/>
32 <Policies>
33
34 <SizeBasedTriggeringPolicy size="10MB"/>
35 Policies>
36
37 <DefaultRolloverStrategy max="50"/>
38 RollingFile>
39 appenders>
40
41 <loggers>
42
43 <logger name="org.springframework" level="error">logger>
44
45 <root level="debug">
46 <appender-ref ref="Console"/>
47 <appender-ref ref="all"/>
48 <appender-ref ref="err"/>
49 root>
50 loggers>
51
52 configuration>