guang
2023-05-06 397c6003970432a8009b81916e55754c1874e03d
提交 | 用户 | age
9e1c8d 1 <?xml version="1.0" encoding="UTF-8"?>
G 2 <!-- status :表示log4j自身日志的打印级别 -->
3 <!-- monitorInterval:含义是每隔300秒重新读取配置文件,可以不重启应用的情况下修改配置 -->
4 <Configuration status="warn" monitorInterval="300">
5     <properties>
6         <property name="INFO_FILE_NAME">info</property>
7         <property name="ERROR_FILE_NAME">error</property>
8         <property name="DEBUG_FILE_NAME">debug</property>
9         <property name="WARN_FILE_NAME">warn</property>
10         <property name="PAY_FILE_NAME">pay</property>
11         <property name="UNIFIED_FOLDER">C:\work\项目\202009旅游及时雨\log\</property>
12     </properties>
13
14     <Appenders>
15         <Console name="Console" target="SYSTEM_OUT">
16             <!-- 左对齐,最小宽度为4;长度>10也可正常显示,不足4用空格补齐 -->
17             <PatternLayout charset="UTF-8" pattern="%d{DEFAULT} [%t] %-4level - %l - %msg%n"/>
18         </Console>
19
20         <!-- fileName:日志位置以及文件名;filePattern:rolling时新建文件的位置以及命名规则。命名文件名称需要细到时分秒是注意不要这么写
21             HH:mm:ss,文件名称不可以包含特殊字符:使用"-"代替 -->
22         <RollingRandomAccessFile name="INFO_FILE"
23                                  fileName="${UNIFIED_FOLDER}/${INFO_FILE_NAME}.log"
24                                  filePattern="${UNIFIED_FOLDER}/base/$${date:yyyy-MM}/${INFO_FILE_NAME}-%d{yyyy-MM-dd}-%i.log.gz"
25                                  append="true">
26
27             <Filters>
28                 <ThresholdFilter level="WARN" onMatch="DENY" onMismatch="NEUTRAL"/>
29                 <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
30             </Filters>
31             <PatternLayout
32                     pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %l - %msg%n"/>
33             <Policies>
34                 <!-- 下面两个策略:满足一个,即会产生一个文件 -->
35                 <!-- 日志文件大于100M,就新建文件 -->
36                 <SizeBasedTriggeringPolicy size="100 MB"/>
37                 <!-- 结合filePattern:精确到dd(天),所以表示每天产生一个日志文件 -->
38                 <TimeBasedTriggeringPolicy interval="1"/>
39             </Policies>
40             <!-- 作用于filePattern中的i,最大20个文件。 -->
41             <DefaultRolloverStrategy max="20"/>
42         </RollingRandomAccessFile>
43
44         <RollingRandomAccessFile name="ERROR_FILE" append="true" fileName="${UNIFIED_FOLDER}/${ERROR_FILE_NAME}.log"
45             filePattern="${UNIFIED_FOLDER}/error/$${date:yyyy-MM}/${ERROR_FILE_NAME}-%d{yyyy-MM}-%i.log.gz">
46             <Filters>
47                 <ThresholdFilter level="fatal" onMatch="DENY" onMismatch="NEUTRAL"/>
48                 <ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
49             </Filters>
50             <PatternLayout
51                     pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %l - %msg%n"/>
52             <Policies>
53                 <SizeBasedTriggeringPolicy size="100 MB"/>
54                 <TimeBasedTriggeringPolicy interval="1"/>
55             </Policies>
56             <DefaultRolloverStrategy max="20"/>
57         </RollingRandomAccessFile>
58
59         <RollingRandomAccessFile name="DEBUG_FILE" fileName="${UNIFIED_FOLDER}/${DEBUG_FILE_NAME}.log"
60             filePattern="${UNIFIED_FOLDER}/error/$${date:yyyy-MM}/${DEBUG_FILE_NAME}-%d{yyyy-MM}-%i.log.gz" append="true">
61             <Filters>
62                 <ThresholdFilter level="fatal" onMatch="DENY" onMismatch="NEUTRAL"/>
63                 <ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="DENY"/>
64             </Filters>
65             <PatternLayout
66                     pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %l - %msg%n"/>
67             <Policies>
68                 <SizeBasedTriggeringPolicy size="100 MB"/>
69                 <TimeBasedTriggeringPolicy interval="1"/>
70             </Policies>
71             <DefaultRolloverStrategy max="20"/>
72         </RollingRandomAccessFile>
73
74         <RollingRandomAccessFile name="WARN_FILE" fileName="${UNIFIED_FOLDER}/${WARN_FILE_NAME}.log"
75                                  filePattern="${UNIFIED_FOLDER}/error/$${date:yyyy-MM}/${WARN_FILE_NAME}-%d{yyyy-MM}-%i.log.gz" append="true">
76             <Filters>
77                 <ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY"/>
78             </Filters>
79             <PatternLayout
80                     pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %l - %msg%n"/>
81             <Policies>
82                 <SizeBasedTriggeringPolicy size="100 MB"/>
83                 <TimeBasedTriggeringPolicy interval="1"/>
84             </Policies>
85             <DefaultRolloverStrategy max="20"/>
86         </RollingRandomAccessFile>
87
88         <RollingRandomAccessFile name="PAY_FILE"
89                                  fileName="${UNIFIED_FOLDER}/${PAY_FILE_NAME}.log"
90                                  filePattern="${UNIFIED_FOLDER}/base/$${date:yyyy-MM}/${PAY_FILE_NAME}-%d{yyyy-MM-dd}-%i.log.gz"
91                                  append="true">
92
93             <Filters>
94                 <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
95             </Filters>
96             <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %l - %msg%n"/>
97             <Policies>
98                 <!-- 下面两个策略:满足一个,即会产生一个文件 -->
99                 <!-- 日志文件大于100M,就新建文件 -->
100                 <SizeBasedTriggeringPolicy size="30MB"/>
101                 <!-- 结合filePattern:精确到dd(天),所以表示每天产生一个日志文件 -->
102                 <TimeBasedTriggeringPolicy interval="1"/>
103             </Policies>
104             <!-- 作用于filePattern中的i,最大20个文件。 -->
105             <DefaultRolloverStrategy max="20"/>
106         </RollingRandomAccessFile>
107
108     </Appenders>
109
110     <Loggers>
111         <!-- additivity="false"表示在该logger中输出的日志不会再延伸到父层logger。这里如果改为true,则会延伸到Root
112             Logger,遵循Root Logger的配置也输出一次。 -->
113         <!-- logger的级别优先于appender的级别,logger为debug,appender为info,debug信息依然可以呈现。即以logger级别为主。 -->
114         <!-- logger可以配置多个 -->
115         <logger name="com.hx.phiappt.controller.TestController" level="info" additivity="false">
116             <appender-ref ref="PAY_FILE"/>
117         </logger>
118
119         <Root level="info">
120             <AppenderRef ref="Console"/>
121             <AppenderRef ref="INFO_FILE"/>
122             <AppenderRef ref="ERROR_FILE"/>
123             <AppenderRef ref="DEBUG_FILE"/>
124             <AppenderRef ref="WARN_FILE"/>
125         </Root>
126     </Loggers>
127 </Configuration>