guang
2023-05-06 56608e48288a97e59fb97340187f57f4a4fcf11e
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
<?xml version="1.0" encoding="UTF-8"?>
<!-- status :表示log4j自身日志的打印级别 -->
<!-- monitorInterval:含义是每隔300秒重新读取配置文件,可以不重启应用的情况下修改配置 -->
<Configuration status="warn" monitorInterval="300">
    <properties>
        <property name="INFO_FILE_NAME">info</property>
        <property name="ERROR_FILE_NAME">error</property>
        <property name="DEBUG_FILE_NAME">debug</property>
        <property name="WARN_FILE_NAME">warn</property>
        <property name="PAY_FILE_NAME">pay</property>
        <property name="UNIFIED_FOLDER">C:\work\项目\202009旅游及时雨\log\</property>
    </properties>
 
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <!-- 左对齐,最小宽度为4;长度>10也可正常显示,不足4用空格补齐 -->
            <PatternLayout charset="UTF-8" pattern="%d{DEFAULT} [%t] %-4level - %l - %msg%n"/>
        </Console>
 
        <!-- fileName:日志位置以及文件名;filePattern:rolling时新建文件的位置以及命名规则。命名文件名称需要细到时分秒是注意不要这么写
            HH:mm:ss,文件名称不可以包含特殊字符:使用"-"代替 -->
        <RollingRandomAccessFile name="INFO_FILE"
                                 fileName="${UNIFIED_FOLDER}/${INFO_FILE_NAME}.log"
                                 filePattern="${UNIFIED_FOLDER}/base/$${date:yyyy-MM}/${INFO_FILE_NAME}-%d{yyyy-MM-dd}-%i.log.gz"
                                 append="true">
 
            <Filters>
                <ThresholdFilter level="WARN" onMatch="DENY" onMismatch="NEUTRAL"/>
                <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
            </Filters>
            <PatternLayout
                    pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %l - %msg%n"/>
            <Policies>
                <!-- 下面两个策略:满足一个,即会产生一个文件 -->
                <!-- 日志文件大于100M,就新建文件 -->
                <SizeBasedTriggeringPolicy size="100 MB"/>
                <!-- 结合filePattern:精确到dd(天),所以表示每天产生一个日志文件 -->
                <TimeBasedTriggeringPolicy interval="1"/>
            </Policies>
            <!-- 作用于filePattern中的i,最大20个文件。 -->
            <DefaultRolloverStrategy max="20"/>
        </RollingRandomAccessFile>
 
        <RollingRandomAccessFile name="ERROR_FILE" append="true" fileName="${UNIFIED_FOLDER}/${ERROR_FILE_NAME}.log"
            filePattern="${UNIFIED_FOLDER}/error/$${date:yyyy-MM}/${ERROR_FILE_NAME}-%d{yyyy-MM}-%i.log.gz">
            <Filters>
                <ThresholdFilter level="fatal" onMatch="DENY" onMismatch="NEUTRAL"/>
                <ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
            </Filters>
            <PatternLayout
                    pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %l - %msg%n"/>
            <Policies>
                <SizeBasedTriggeringPolicy size="100 MB"/>
                <TimeBasedTriggeringPolicy interval="1"/>
            </Policies>
            <DefaultRolloverStrategy max="20"/>
        </RollingRandomAccessFile>
 
        <RollingRandomAccessFile name="DEBUG_FILE" fileName="${UNIFIED_FOLDER}/${DEBUG_FILE_NAME}.log"
            filePattern="${UNIFIED_FOLDER}/error/$${date:yyyy-MM}/${DEBUG_FILE_NAME}-%d{yyyy-MM}-%i.log.gz" append="true">
            <Filters>
                <ThresholdFilter level="fatal" onMatch="DENY" onMismatch="NEUTRAL"/>
                <ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="DENY"/>
            </Filters>
            <PatternLayout
                    pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %l - %msg%n"/>
            <Policies>
                <SizeBasedTriggeringPolicy size="100 MB"/>
                <TimeBasedTriggeringPolicy interval="1"/>
            </Policies>
            <DefaultRolloverStrategy max="20"/>
        </RollingRandomAccessFile>
 
        <RollingRandomAccessFile name="WARN_FILE" fileName="${UNIFIED_FOLDER}/${WARN_FILE_NAME}.log"
                                 filePattern="${UNIFIED_FOLDER}/error/$${date:yyyy-MM}/${WARN_FILE_NAME}-%d{yyyy-MM}-%i.log.gz" append="true">
            <Filters>
                <ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY"/>
            </Filters>
            <PatternLayout
                    pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %l - %msg%n"/>
            <Policies>
                <SizeBasedTriggeringPolicy size="100 MB"/>
                <TimeBasedTriggeringPolicy interval="1"/>
            </Policies>
            <DefaultRolloverStrategy max="20"/>
        </RollingRandomAccessFile>
 
        <RollingRandomAccessFile name="PAY_FILE"
                                 fileName="${UNIFIED_FOLDER}/${PAY_FILE_NAME}.log"
                                 filePattern="${UNIFIED_FOLDER}/base/$${date:yyyy-MM}/${PAY_FILE_NAME}-%d{yyyy-MM-dd}-%i.log.gz"
                                 append="true">
 
            <Filters>
                <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
            </Filters>
            <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %l - %msg%n"/>
            <Policies>
                <!-- 下面两个策略:满足一个,即会产生一个文件 -->
                <!-- 日志文件大于100M,就新建文件 -->
                <SizeBasedTriggeringPolicy size="30MB"/>
                <!-- 结合filePattern:精确到dd(天),所以表示每天产生一个日志文件 -->
                <TimeBasedTriggeringPolicy interval="1"/>
            </Policies>
            <!-- 作用于filePattern中的i,最大20个文件。 -->
            <DefaultRolloverStrategy max="20"/>
        </RollingRandomAccessFile>
 
    </Appenders>
 
    <Loggers>
        <!-- additivity="false"表示在该logger中输出的日志不会再延伸到父层logger。这里如果改为true,则会延伸到Root
            Logger,遵循Root Logger的配置也输出一次。 -->
        <!-- logger的级别优先于appender的级别,logger为debug,appender为info,debug信息依然可以呈现。即以logger级别为主。 -->
        <!-- logger可以配置多个 -->
        <logger name="com.hx.phiappt.controller.TestController" level="info" additivity="false">
            <appender-ref ref="PAY_FILE"/>
        </logger>
 
        <Root level="info">
            <AppenderRef ref="Console"/>
            <AppenderRef ref="INFO_FILE"/>
            <AppenderRef ref="ERROR_FILE"/>
            <AppenderRef ref="DEBUG_FILE"/>
            <AppenderRef ref="WARN_FILE"/>
        </Root>
    </Loggers>
</Configuration>