logback-spring.xml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. ~ Copyright (c) 2020 pig4cloud Authors. All Rights Reserved.
  4. ~
  5. ~ Licensed under the Apache License, Version 2.0 (the "License");
  6. ~ you may not use this file except in compliance with the License.
  7. ~ You may obtain a copy of the License at
  8. ~
  9. ~ http://www.apache.org/licenses/LICENSE-2.0
  10. ~
  11. ~ Unless required by applicable law or agreed to in writing, software
  12. ~ distributed under the License is distributed on an "AS IS" BASIS,
  13. ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. ~ See the License for the specific language governing permissions and
  15. ~ limitations under the License.
  16. -->
  17. <configuration debug="false" scan="false">
  18. <springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue=""/>
  19. <property name="log.path" value="logs/${spring.application.name}"/>
  20. <!-- 彩色日志格式 -->
  21. <property name="CONSOLE_LOG_PATTERN"
  22. value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
  23. <property name="FILE_LOG_PATTERN" value=":%d{yyyy-MM-dd HH:mm:ss.SSS} %5p %t %c{1}: %m%n"/>
  24. <!-- 彩色日志依赖的渲染类 -->
  25. <conversionRule conversionWord="clr" class="org.springframework.boot.logging.logback.ColorConverter"/>
  26. <conversionRule conversionWord="wex"
  27. class="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
  28. <conversionRule conversionWord="wEx"
  29. class="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
  30. <!-- Console log output -->
  31. <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
  32. <encoder>
  33. <pattern>${CONSOLE_LOG_PATTERN}</pattern>
  34. </encoder>
  35. </appender>
  36. <!-- Log file debug output -->
  37. <appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
  38. <file>${log.path}/debug.log</file>
  39. <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
  40. <fileNamePattern>${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
  41. <maxFileSize>50MB</maxFileSize>
  42. <maxHistory>30</maxHistory>
  43. </rollingPolicy>
  44. <encoder>
  45. <pattern>${FILE_LOG_PATTERN}</pattern>
  46. </encoder>
  47. </appender>
  48. <!-- Log file error output -->
  49. <appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
  50. <file>${log.path}/error.log</file>
  51. <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
  52. <fileNamePattern>${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
  53. <maxFileSize>50MB</maxFileSize>
  54. <maxHistory>30</maxHistory>
  55. </rollingPolicy>
  56. <encoder>
  57. <pattern>${FILE_LOG_PATTERN}</pattern>
  58. </encoder>
  59. <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
  60. <level>ERROR</level>
  61. </filter>
  62. </appender>
  63. <!--nacos 心跳 INFO 屏蔽-->
  64. <logger name="com.alibaba.nacos" level="OFF">
  65. <appender-ref ref="error"/>
  66. </logger>
  67. <!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
  68. <root level="INFO">
  69. <appender-ref ref="console"/>
  70. <appender-ref ref="debug"/>
  71. <appender-ref ref="error"/>
  72. </root>
  73. </configuration>