我自己常用的一个logback配置框架,有需要再在上面添加:
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!-- <configuration scan="true" scanPeriod="60 seconds"> -->
3 <configuration>
4 <!-- print configuration status on console -->
5 <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener"/>
6
7 <!-- Beagle: eclipse plugin -->
8 <consolePlugin />
9
10 <!-- log path -->
11 <property name="LOG_PATH" value="d:/log" />
12 <!-- <property resource="resource1.properties" /> -->
13
14 <!-- console appender -->
15 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
16 <encoder>
17 <pattern>
18 %d{HH:mm:ss.SSS} [%t] %-5p %c{1} - %m%n
19 </pattern>
20 </encoder>
21 </appender>
22
23 <!-- default appender -->
24 <appender name="COMMON-DEFAULT-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
25 <File>${LOG_PATH}/common-default.log</File>
26 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
27 <FileNamePattern>
28 ${LOG_PATH}/common-default.%d.log.gz
29 <!-- ${LOG_PATH}/%d{yyyy-MM,aux}/common-default.%d.log.gz -->
30 </FileNamePattern>
31 </rollingPolicy>
32 <encoder>
33 <Pattern>
34 %d [%t] %-5p %c{1} - %m%n
35 </Pattern>
36 </encoder>
37 <!-- <immediateFlush>false</immediateFlush> -->
38 </appender>
39
40 <!-- error appender -->
41 <appender name="COMMON-ERROR-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
42 <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
43 <level>ERROR</level>
44 </filter>
45 <File>${LOG_PATH}/common-error.log</File>
46 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
47 <FileNamePattern>
48 ${LOG_PATH}/common-error.%d.log.gz
49 <!-- ${LOG_PATH}/%d{yyyy-MM,aux}/common-error.%d.log.gz -->
50 </FileNamePattern>
51 </rollingPolicy>
52 <encoder>
53 <Pattern>
54 %d [%t] %-5p %c{1} - %m%n
55 </Pattern>
56 </encoder>
57 <!-- <immediateFlush>false</immediateFlush> -->
58 </appender>
59
60 <!-- root logger -->
61 <root>
62 <level value="DEBUG"/>
63 <appender-ref ref="STDOUT"/>
64 <appender-ref ref="COMMON-DEFAULT-APPENDER"/>
65 <appender-ref ref="COMMON-ERROR-APPENDER"/>
66 </root>
67
68 </configuration>
69