zlogback.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration scan="false">
  3. <contextName>cbkj</contextName>
  4. <!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
  5. <property name="LOG_PATH" value="/app/logs"/>
  6. <!--设置系统日志目录-->
  7. <property name="APPDIR" value="systemLogs"/>
  8. <!--设置日期格式 -->
  9. <timestamp key="bySecond" datePattern="yyyyMMdd'T'HHmmss"/>
  10. <!-- %m输出的信息,%p日志级别,%t线程名,%d日期,%c类的全名,,,, -->
  11. <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
  12. <encoder>
  13. <!--<pattern>%d %p (%file:%line\)- %m%n</pattern>-->
  14. <!--格式化输出:%d:表示日期 %thread:表示线程名 %-5level:级别从左显示5个字符宽度 %msg:日志消息 %n:是换行符-->
  15. <pattern>1-%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger - %msg%n</pattern>
  16. <charset>utf-8</charset>
  17. </encoder>
  18. </appender>
  19. <!--
  20. 说明:
  21. 1、日志级别及文件
  22. 日志记录采用分级记录,级别与日志文件名相对应,不同级别的日志信息记录到不同的日志文件中
  23. 例如:error级别记录到log_error_xxx.log或log_error.log(该文件为当前记录的日志文件),而log_error_xxx.log为归档日志,
  24. 日志文件按日期记录,同一天内,若日志文件大小等于或大于2M,则按0、1、2...顺序分别命名
  25. 例如log-level-2013-12-21.0.log
  26. 其它级别的日志也是如此。
  27. 2、文件路径
  28. 若开发、测试用,在Eclipse中运行项目,则到Eclipse的安装路径查找logs文件夹,以相对路径../logs。
  29. 若部署到Tomcat下,则在Tomcat下的logs文件中
  30. 3、Appender
  31. FILEERROR对应error级别,文件名以log-error-xxx.log形式命名
  32. FILEWARN对应warn级别,文件名以log-warn-xxx.log形式命名
  33. FILEINFO对应info级别,文件名以log-info-xxx.log形式命名
  34. FILEDEBUG对应debug级别,文件名以log-debug-xxx.log形式命名
  35. CONSOLE将日志信息输出到控制上,为方便开发测试使用
  36. -->
  37. <!-- 日志记录器,日期滚动记录 -->
  38. <appender name="FILEERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
  39. <!-- 正在记录的日志文件的路径及文件名 -->
  40. <file>${LOG_PATH}/${APPDIR}/${bySecond}_error.log</file>
  41. <!-- 追加方式记录日志 -->
  42. <append>true</append>
  43. <!-- 日志记录器的滚动策略,按日期,按大小记录 -->
  44. <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  45. <!-- 归档的日志文件的路径,例如今天是2013-12-21日志,当前写的日志文件路径为file节点指定,可以将此文件与file指定文件路径设置为不同路径,从而将当前日志文件或归档日志文件置不同的目录。
  46. 而2013-12-21的日志文件在由fileNamePattern指定。%d{yyyy-MM-dd}指定日期格式,%i指定索引 -->
  47. <fileNamePattern>${LOG_PATH}/${APPDIR}/error/log-error-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  48. <!--日志文件保留天数-->
  49. <MaxHistory>30</MaxHistory>
  50. <!-- 除按日志记录之外,还配置了日志文件不能超过2M,若超过2M,日志文件会以索引0开始,命名日志文件,例如log-error-2013-12-21.0.log -->
  51. <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
  52. <maxFileSize>20MB</maxFileSize>
  53. </timeBasedFileNamingAndTriggeringPolicy>
  54. </rollingPolicy>
  55. <!-- 日志文件的格式 -->
  56. <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
  57. <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger Line:%-3L - %msg%n</pattern>
  58. <charset>utf-8</charset>
  59. </encoder>
  60. <!-- 此日志文件只记录error级别的 -->
  61. <filter class="ch.qos.logback.classic.filter.LevelFilter">
  62. <level>error</level>
  63. <onMatch>ACCEPT</onMatch>
  64. <onMismatch>DENY</onMismatch>
  65. </filter>
  66. </appender>
  67. <!-- 日志记录器,日期滚动记录 1号接口 -->
  68. <appender name="one" class="ch.qos.logback.core.rolling.RollingFileAppender">
  69. <file>${LOG_PATH}/one/${bySecond}_interface1.log</file>
  70. <append>true</append>
  71. <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  72. <fileNamePattern>${LOG_PATH}/one/log-interface1-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  73. <MaxHistory>10</MaxHistory>
  74. <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
  75. <maxFileSize>20MB</maxFileSize>
  76. </timeBasedFileNamingAndTriggeringPolicy>
  77. </rollingPolicy>
  78. <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
  79. <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger Line:%-3L - %msg%n</pattern>
  80. <charset>utf-8</charset>
  81. </encoder>
  82. <filter class="ch.qos.logback.classic.filter.LevelFilter">
  83. <level>INFO</level>
  84. <onMatch>ACCEPT</onMatch>
  85. <onMismatch>DENY</onMismatch>
  86. </filter>
  87. </appender>
  88. <!-- 日志记录器,日期滚动记录 3号接口 -->
  89. <appender name="three" class="ch.qos.logback.core.rolling.RollingFileAppender">
  90. <file>${LOG_PATH}/three/${bySecond}_interface3.log</file>
  91. <append>true</append>
  92. <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  93. <fileNamePattern>${LOG_PATH}/three/log-interface3-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  94. <MaxHistory>10</MaxHistory>
  95. <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
  96. <maxFileSize>20MB</maxFileSize>
  97. </timeBasedFileNamingAndTriggeringPolicy>
  98. </rollingPolicy>
  99. <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
  100. <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger Line:%-3L - %msg%n</pattern>
  101. <charset>utf-8</charset>
  102. </encoder>
  103. <filter class="ch.qos.logback.classic.filter.LevelFilter">
  104. <level>INFO</level>
  105. <onMatch>ACCEPT</onMatch>
  106. <onMismatch>DENY</onMismatch>
  107. </filter>
  108. </appender>
  109. <!-- 日志记录器,日期滚动记录 4号接口 -->
  110. <appender name="four" class="ch.qos.logback.core.rolling.RollingFileAppender">
  111. <file>${LOG_PATH}/four/${bySecond}_interface4.log</file>
  112. <append>true</append>
  113. <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  114. <fileNamePattern>${LOG_PATH}/four/log-interface4-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  115. <MaxHistory>10</MaxHistory>
  116. <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
  117. <maxFileSize>20MB</maxFileSize>
  118. </timeBasedFileNamingAndTriggeringPolicy>
  119. </rollingPolicy>
  120. <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
  121. <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger Line:%-3L - %msg%n</pattern>
  122. <charset>utf-8</charset>
  123. </encoder>
  124. <filter class="ch.qos.logback.classic.filter.LevelFilter">
  125. <level>INFO</level>
  126. <onMatch>ACCEPT</onMatch>
  127. <onMismatch>DENY</onMismatch>
  128. </filter>
  129. </appender>
  130. <logger name="org.springframework.data.mybatis" level="DEBUG"/>
  131. <logger name="org.springframework.aop.aspectj" level="DEBUG"/>
  132. <logger name="org.apache.xerces" level="INFO"/>
  133. <logger name="javax.activation" level="WARN"/>
  134. <logger name="javax.mail" level="WARN"/>
  135. <logger name="javax.xml.bind" level="WARN"/>
  136. <logger name="ch.qos.logback" level="INFO"/>
  137. <logger name="com.codahale.metrics" level="WARN"/>
  138. <logger name="com.ryantenney" level="WARN"/>
  139. <logger name="com.sun" level="WARN"/>
  140. <logger name="com.zaxxer" level="WARN"/>
  141. <logger name="io.undertow" level="WARN"/>
  142. <logger name="net.sf.ehcache" level="WARN"/>
  143. <logger name="org.apache" level="WARN"/>
  144. <logger name="org.apache.catalina.startup.DigesterFactory" level="OFF"/>
  145. <logger name="org.bson" level="WARN"/>
  146. <logger name="org.hibernate.validator" level="WARN"/>
  147. <logger name="org.hibernate" level="WARN"/>
  148. <logger name="org.hibernate.ejb.HibernatePersistence" level="OFF"/>
  149. <logger name="org.springframework.web" level="INFO"/>
  150. <logger name="org.springframework.security" level="WARN"/>
  151. <logger name="org.springframework.cache" level="WARN"/>
  152. <logger name="org.thymeleaf" level="WARN"/>
  153. <logger name="sun.rmi" level="WARN"/>
  154. <logger name="sun.rmi.transport" level="WARN"/>
  155. <logger name="org.springframework.core" level="ERROR"/>
  156. <logger name="jdbc.connection" level="ERROR"/>
  157. <logger name="jdbc.resultset" level="ERROR"/>
  158. <logger name="jdbc.resultsettable" level="INFO"/>
  159. <logger name="jdbc.audit" level="ERROR"/>
  160. <!--<logger name="jdbc.sqltiming" level="ERROR"/>
  161. <logger name="jdbc.sqlonly" level="INFO"/>-->
  162. <!--生产环境使用注释内的配置-->
  163. <logger name="jdbc.sqltiming" level="INFO"/>
  164. <logger name="jdbc.sqlonly" level="OFF"/>
  165. <logger name="com.jiuzhekan.cbkj.mapper" level="DEBUG"/>
  166. <!-- 日志级别变更穿透 -->
  167. <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
  168. <resetJUL>true</resetJUL>
  169. </contextListener>
  170. <root level="INFO">
  171. <appender-ref ref="STDOUT"/>
  172. <appender-ref ref="FILEERROR"/>
  173. <!-- <appender-ref ref="FILEINFO"/>-->
  174. <!-- <appender-ref ref="FILEWARN"/>-->
  175. </root>
  176. <logger name="one" additivity="true">
  177. <appender-ref ref="one"/>
  178. </logger>
  179. <logger name="three" additivity="true">
  180. <appender-ref ref="three"/>
  181. </logger>
  182. <logger name="four" additivity="true">
  183. <appender-ref ref="four"/>
  184. </logger>
  185. </configuration>