logback-spring.xml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration debug="false" scan="false">
  3. <springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue=""/>
  4. <property name="log.path" value="logs"/>
  5. <!-- 彩色日志格式 -->
  6. <property name="CONSOLE_LOG_PATTERN"
  7. 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}}"/>
  8. <!-- 彩色日志依赖的渲染类 -->
  9. <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
  10. <conversionRule conversionWord="wex"
  11. converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
  12. <conversionRule conversionWord="wEx"
  13. converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
  14. <!-- Console log output -->
  15. <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
  16. <encoder>
  17. <pattern>${CONSOLE_LOG_PATTERN}</pattern>
  18. </encoder>
  19. </appender>
  20. <!-- Log file error output -->
  21. <appender name="errorLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
  22. <file>${log.path}/error/error.log</file>
  23. <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
  24. <fileNamePattern>${log.path}/error/%d{yyyy-MM,aux}/error-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  25. <maxFileSize>50MB</maxFileSize>
  26. </rollingPolicy>
  27. <encoder>
  28. <pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
  29. </encoder>
  30. <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
  31. <level>ERROR</level>
  32. </filter>
  33. </appender>
  34. <!-- Log file debug output -->
  35. <appender name="sourceLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
  36. <!-- 过滤器,只记录WARN级别的日志 -->
  37. <filter class="ch.qos.logback.classic.filter.LevelFilter">
  38. <level>INFO</level>
  39. <onMatch>ACCEPT</onMatch>
  40. <onMismatch>DENY</onMismatch>
  41. </filter>
  42. <file>${log.path}/source/source.log</file>
  43. <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
  44. <fileNamePattern>${log.path}/source/%d{yyyy-MM,aux}/source-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  45. <maxFileSize>50MB</maxFileSize>
  46. </rollingPolicy>
  47. <encoder>
  48. <pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
  49. </encoder>
  50. </appender>
  51. <!-- Log file debug output -->
  52. <appender name="chargeLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
  53. <!-- 过滤器,只记录WARN级别的日志 -->
  54. <filter class="ch.qos.logback.classic.filter.LevelFilter">
  55. <level>INFO</level>
  56. <onMatch>ACCEPT</onMatch>
  57. <onMismatch>DENY</onMismatch>
  58. </filter>
  59. <file>${log.path}/charge/charge.log</file>
  60. <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
  61. <fileNamePattern>${log.path}/charge/%d{yyyy-MM,aux}/charge-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  62. <maxFileSize>50MB</maxFileSize>
  63. </rollingPolicy>
  64. <encoder>
  65. <pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
  66. </encoder>
  67. </appender>
  68. <appender name="testLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
  69. <!-- 过滤器,只记录WARN级别的日志 -->
  70. <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
  71. <level>INFO</level>
  72. </filter>
  73. <file>${log.path}/test/test.log</file>
  74. <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
  75. <fileNamePattern>${log.path}/test/test-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  76. <maxFileSize>50MB</maxFileSize>
  77. </rollingPolicy>
  78. <encoder>
  79. <pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
  80. </encoder>
  81. </appender>
  82. <!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
  83. <root level="INFO">
  84. <appender-ref ref="console"/>
  85. <appender-ref ref="sourceLog"/>
  86. <appender-ref ref="errorLog"/>
  87. </root>
  88. <logger name="CHARGE_LOGGER" additivity="false">
  89. <level value="INFO" />
  90. <appender-ref ref="chargeLog" />
  91. </logger>
  92. <logger name="TEST_LOGGER" additivity="false">
  93. <level value="INFO" />
  94. <appender-ref ref="testLog" />
  95. </logger>
  96. </configuration>