1 <?xml version="1.0" encoding="UTF-8" ?> 2 <configuration scan="false" scanPeriod="60000" debug="true"> 3 4 <!--用来定义变量值,它有两个属性name和value,通过<property>定义的值会被插入到logger上下文中--> 5 <property name="APP_NAME" value="${log.app.name}" /> 6 <property name="LOG_HOME" value="${log.home}" /> 7 <property name="LOG_KEEP_TIME" value="60" /> 8 9 <!--用来设置上下文名称,每个logger都关联到logger上下文,默认上下文名称为default--> 10 <contextName>${APP_NAME}</contextName> 11 12 <!--子节点<appender>:负责写日志的组件,它有两个必要属性name和class。name指定appender名称,class指定appender的全限定名--> 13 <!--ConsoleAppender 把日志输出到控制台--> 14 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> 15 <!--<encoder> 对日志进行格式化--> 16 <encoder> 17 <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度, %msg:日志消息,%n是换行符--> 18 <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%-4level] [%logger{36}] [%msg]%n</pattern> 19 <charset>UTF-8</charset> 20 </encoder> 21 </appender> 22 23 <!--RollingFileAppender:滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件--> 24 <appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> 25 <encoder> 26 <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%-4level] [%logger{36}] [%msg]%n</pattern> 27 <charset>UTF-8</charset> 28 </encoder> 29 <!--rollingPolicy 当发生滚动时,决定RollingFileAppender的行为,涉及文件移动和重命名。属性class定义具体的滚动策略类--> 30 <!--class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy": 最常用的滚动策略,它根据时间来制定滚动策略,既负责滚动也负责出发滚动--> 31 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 32 <!--日志文件输出的文件名--> 33 <FileNamePattern>${LOG_HOME}/nova.${APP_NAME}.debug.%d{yyyy-MM-dd}.log</FileNamePattern> 34 <!--可选节点,控制保留的归档文件的最大数量,超出数量就删除旧文件。假设设置每个月滚动,且<maxHistory>是6,则只保存最近6个月的文件,删除之前的旧文件。 35 注意,删除旧文件是,那些为了归档而创建的目录也会被删除。--> 36 <MaxHistory>${LOG_KEEP_TIME}</MaxHistory> 37 </rollingPolicy> 38 <filter class="ch.qos.logback.classic.filter.LevelFilter"> 39 <level>DEBUG</level> 40 <onMatch>ACCEPT</onMatch> 41 <onMismatch>DENY</onMismatch> 42 </filter> 43 </appender> 44 45 <appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> 46 <encoder> 47 <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%-4level] [%logger{36}] [%msg]%n</pattern> 48 <charset>UTF-8</charset> 49 </encoder> 50 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 51 <FileNamePattern>${LOG_HOME}/nova.${APP_NAME}.info.%d{yyyy-MM-dd}.log</FileNamePattern> 52 <MaxHistory>${LOG_KEEP_TIME}</MaxHistory> 53 </rollingPolicy> 54 <filter class="ch.qos.logback.classic.filter.LevelFilter"> 55 <level>INFO</level> 56 <onMatch>ACCEPT</onMatch> 57 <onMismatch>DENY</onMismatch> 58 </filter> 59 </appender> 60 61 <appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> 62 <encoder> 63 <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%-4level] [%logger{36}] - [%msg]%n</pattern> 64 <charset>UTF-8</charset> 65 </encoder> 66 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 67 <FileNamePattern>${LOG_HOME}/nova.${APP_NAME}.error.%d{yyyy-MM-dd}.log</FileNamePattern> 68 <MaxHistory>${LOG_KEEP_TIME}</MaxHistory> 69 </rollingPolicy> 70 <filter class="ch.qos.logback.classic.filter.LevelFilter"> 71 <level>ERROR</level> 72 <onMatch>ACCEPT</onMatch> 73 <onMismatch>DENY</onMismatch> 74 </filter> 75 </appender> 76 77 <appender name="THRIFT_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> 78 <encoder> 79 <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%-4level] [%logger{36}] - [%msg]%n</pattern> 80 <charset>UTF-8</charset> 81 </encoder> 82 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 83 <FileNamePattern>${LOG_HOME}/nova.${APP_NAME}.thrift.%d{yyyy-MM-dd}.log</FileNamePattern> 84 <MaxHistory>${LOG_KEEP_TIME}</MaxHistory> 85 </rollingPolicy> 86 </appender> 87 88 <appender name="EXPRESS_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> 89 <encoder> 90 <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%-5level] [%logger{36}:%line] - [%msg]%n</pattern> 91 <charset>UTF-8</charset> 92 </encoder> 93 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 94 <FileNamePattern>${LOG_HOME}/nova.${APP_NAME}.express.%d{yyyy-MM}.log</FileNamePattern> 95 <MaxHistory>6</MaxHistory> 96 </rollingPolicy> 97 </appender> 98 99 <!--用来设置某一个包或具体的某一个类的日志打印级别、以及指定<appender>--> 100 <!--name:用来指定此logger约束的某一个包或者具体的某一个类, 101 level: 用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL和OFF 102 addtivity: 是否向上级logger传递打印信息。默认是true--> 103 <logger name="ch.qos.logback" level="ERROR" additivity="true" /> 104 <logger name="org.springframework" level="INFO" additivity="true" /> 105 <!--<logger name="com.xiaoju.ecom.rpc" level="INFO" additivity="false"> 106 <appender-ref ref="THRIFT_FILE" /> 107 </logger>--> 108 <logger name="com.xman.rainbow.car" level="DEBUG" additivity="false"> 109 <appender-ref ref="STDOUT" /> 110 <appender-ref ref="DEBUG_FILE" /> 111 <appender-ref ref="INFO_FILE" /> 112 <appender-ref ref="ERROR_FILE" /> 113 </logger> 114 115 <logger name="com.xiaoju.fcar.bis.express.logger" level="INFO" additivity="false"> 116 <appender-ref ref="EXPRESS_FILE" /> 117 </logger> 118 119 <!--表示把>=INFO级别的日志都输出到控制台--> 120 <root level="INFO"> 121 <appender-ref ref="STDOUT" /> 122 </root> 123 124 </configuration>