02-logback-spring.xml日志配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="6000000" debug="false">

<property name="LOG_PATTERN" value="%date{HH:mm:ss.SSS} %-5p [%t:%c{1}:%L] - %msg%n"/>
<!--
将日志文件的保存位置修改为自定义的路径,当前的配置是在项目的目录中新建一个logs目录,在logs中创建具体的模块的日志目录.
-->
<property name="LOG_PATH" value="./logs/cache/"/>
<!-- 系统级配置文件 开始 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>${LOG_PATTERN}</Pattern>
</layout>
</appender>

<!-- stdout -->
<appender name="rootstdout"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${LOG_PATH}rootstdout.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<FileNamePattern>${LOG_PATH}rootstdout.%i.log.zip</FileNamePattern>
<MinIndex>1</MinIndex>
<MaxIndex>20</MaxIndex>
</rollingPolicy>
<triggeringPolicy
class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>${LOG_PATTERN}</Pattern>
</layout>
</appender>

<!-- debug -->
<appender name="rootDebug" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${LOG_PATH}root-debug.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<FileNamePattern>${LOG_PATH}root-debug.%i.log.zip</FileNamePattern>
<MinIndex>1</MinIndex>
<MaxIndex>10</MaxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>${LOG_PATTERN}</Pattern>
</layout>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>DEBUG</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>

<!-- info -->
<appender name="rootInfo" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${LOG_PATH}root-info.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<FileNamePattern>${LOG_PATH}root-info.%i.log.zip</FileNamePattern>
<MinIndex>1</MinIndex>
<MaxIndex>10</MaxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>${LOG_PATTERN}</Pattern>
</layout>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>

<!-- warn -->
<appender name="rootWarn" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${LOG_PATH}root-warn.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<FileNamePattern>${LOG_PATH}root-warn.%i.log.zip</FileNamePattern>
<MinIndex>1</MinIndex>
<MaxIndex>10</MaxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>${LOG_PATTERN}</Pattern>
</layout>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>

<!-- error -->
<appender name="rootError" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${LOG_PATH}root-error.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${LOG_PATH}root-error.%d{yyyy-MM-dd}.log</FileNamePattern>
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>${LOG_PATTERN}</Pattern>
</layout>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>Error</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>

<springProfile name="local">
<root level="info">
<!-- 本地测试时使用,将日志打印到控制台,实际部署时请注释掉 -->
<appender-ref ref="STDOUT"/>
<appender-ref ref="rootstdout"/>
<appender-ref ref="rootDebug"/>
<appender-ref ref="rootInfo"/>
<appender-ref ref="rootWarn"/>
<appender-ref ref="rootError"/>
</root>
</springProfile>

<springProfile name="dev">
<root level="info">
<!-- 本地测试时使用,将日志打印到控制台,实际部署时请注释掉 -->
<appender-ref ref="rootstdout"/>
<appender-ref ref="rootDebug"/>
<appender-ref ref="rootInfo"/>
<appender-ref ref="rootWarn"/>
<appender-ref ref="rootError"/>
</root>
</springProfile>

<springProfile name="prod">
<root level="info">
<!-- 本地测试时使用,将日志打印到控制台,实际部署时请注释掉 -->
<appender-ref ref="rootstdout"/>
<appender-ref ref="rootDebug"/>
<appender-ref ref="rootInfo"/>
<appender-ref ref="rootWarn"/>
<appender-ref ref="rootError"/>
</root>
</springProfile>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<jmxConfigurator/>
</configuration>

02-logback-spring.xml日志配置
https://janycode.github.io/2016/04/28/09_调试测试/01_日志记录/02-logback-spring.xml日志配置 (copy)/
作者
Jerry(姜源)
发布于
2016年4月28日
许可协议