logback.xml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration>
  3. <include resource="org/springframework/boot/logging/logback/base.xml" />
  4. <logger name="org.springframework.web" level="INFO"/>
  5. <logger name="org.springboot.sample" level="TRACE" />
  6. <!-- 开发、测试环境 -->
  7. <springProfile name="dev,test">
  8. <logger name="org.springframework.web" level="INFO"/>
  9. <logger name="org.springboot.sample" level="INFO" />
  10. <logger name="com.xjrsoft" level="DEBUG" />
  11. </springProfile>
  12. <!-- 生产环境 -->
  13. <springProfile name="prod">
  14. <logger name="org.springframework.web" level="ERROR"/>
  15. <logger name="org.springboot.sample" level="ERROR" />
  16. <logger name="com.xjrsoft" level="ERROR" />
  17. </springProfile>
  18. <!-- 日志存放路径 -->
  19. <property name="log.path" value="./logs" />
  20. <!-- 日志输出格式 -->
  21. <property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
  22. <!-- 控制台输出 -->
  23. <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
  24. <encoder>
  25. <pattern>${log.pattern}</pattern>
  26. </encoder>
  27. </appender>
  28. <!-- 系统日志输出 -->
  29. <appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
  30. <file>${log.path}/sys-info.log</file>
  31. <!-- 循环政策:基于时间创建日志文件 -->
  32. <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  33. <!-- 日志文件名格式 -->
  34. <fileNamePattern>${log.path}/sys-info.%d{yyyy-MM-dd}.log</fileNamePattern>
  35. <!-- 日志最大的历史 60天 -->
  36. <maxHistory>60</maxHistory>
  37. </rollingPolicy>
  38. <encoder>
  39. <pattern>${log.pattern}</pattern>
  40. </encoder>
  41. <filter class="ch.qos.logback.classic.filter.LevelFilter">
  42. <!-- 过滤的级别 -->
  43. <level>INFO</level>
  44. <!-- 匹配时的操作:接收(记录) -->
  45. <onMatch>ACCEPT</onMatch>
  46. <!-- 不匹配时的操作:拒绝(不记录) -->
  47. <onMismatch>DENY</onMismatch>
  48. </filter>
  49. </appender>
  50. <appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
  51. <file>${log.path}/sys-error.log</file>
  52. <!-- 循环政策:基于时间创建日志文件 -->
  53. <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  54. <!-- 日志文件名格式 -->
  55. <fileNamePattern>${log.path}/sys-error.%d{yyyy-MM-dd}.log</fileNamePattern>
  56. <!-- 日志最大的历史 60天 -->
  57. <maxHistory>60</maxHistory>
  58. </rollingPolicy>
  59. <encoder>
  60. <pattern>${log.pattern}</pattern>
  61. </encoder>
  62. <filter class="ch.qos.logback.classic.filter.LevelFilter">
  63. <!-- 过滤的级别 -->
  64. <level>ERROR</level>
  65. <!-- 匹配时的操作:接收(记录) -->
  66. <onMatch>ACCEPT</onMatch>
  67. <!-- 不匹配时的操作:拒绝(不记录) -->
  68. <onMismatch>DENY</onMismatch>
  69. </filter>
  70. </appender>
  71. <!-- 用户访问日志输出 -->
  72. <appender name="sys-user" class="ch.qos.logback.core.rolling.RollingFileAppender">
  73. <file>${log.path}/sys-user.log</file>
  74. <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  75. <!-- 按天回滚 daily -->
  76. <fileNamePattern>${log.path}/sys-user.%d{yyyy-MM-dd}.log</fileNamePattern>
  77. <!-- 日志最大的历史 60天 -->
  78. <maxHistory>60</maxHistory>
  79. </rollingPolicy>
  80. <encoder>
  81. <pattern>${log.pattern}</pattern>
  82. </encoder>
  83. </appender>
  84. <!-- 系统模块日志级别控制 -->
  85. <logger name="com.xjrsoft" level="info" />
  86. <!-- Spring日志级别控制 -->
  87. <logger name="org.springframework" level="info" />
  88. <root level="info">
  89. <appender-ref ref="console" />
  90. </root>
  91. <!--系统操作日志-->
  92. <root level="info">
  93. <appender-ref ref="file_info" />
  94. <appender-ref ref="file_error" />
  95. </root>
  96. <!--系统用户操作日志-->
  97. <logger name="sys-user" level="info">
  98. <appender-ref ref="sys-user"/>
  99. </logger>
  100. </configuration>