1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <configuration >
3+ <!-- 引入Spring Boot默认配置 -->
4+ <include resource =" org/springframework/boot/logging/logback/defaults.xml" />
5+
6+ <!-- 定义日志文件存储位置 -->
7+ <property name =" LOG_HOME" value =" ./logs" />
8+
9+ <!-- 控制台输出配置 -->
10+ <appender name =" CONSOLE" class =" ch.qos.logback.core.ConsoleAppender" >
11+ <encoder >
12+ <pattern >%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{50}) - %msg%n</pattern >
13+ <charset >UTF-8</charset >
14+ </encoder >
15+ </appender >
16+
17+ <!-- 文件输出配置 - 所有日志 -->
18+ <appender name =" FILE" class =" ch.qos.logback.core.rolling.RollingFileAppender" >
19+ <file >${LOG_HOME}/xiaozhi-esp32-server-java.log</file >
20+ <rollingPolicy class =" ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy" >
21+ <fileNamePattern >${LOG_HOME}/xiaozhi-esp32-server-java.%d{yyyy-MM-dd}.%i.log</fileNamePattern >
22+ <maxFileSize >10MB</maxFileSize >
23+ <maxHistory >30</maxHistory >
24+ <totalSizeCap >2GB</totalSizeCap >
25+ </rollingPolicy >
26+ <encoder >
27+ <pattern >%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern >
28+ <charset >UTF-8</charset >
29+ </encoder >
30+ </appender >
31+
32+ <!-- 文件输出配置 - 仅错误日志 -->
33+ <appender name =" ERROR_FILE" class =" ch.qos.logback.core.rolling.RollingFileAppender" >
34+ <file >${LOG_HOME}/error.log</file >
35+ <filter class =" ch.qos.logback.classic.filter.ThresholdFilter" >
36+ <level >ERROR</level >
37+ </filter >
38+ <rollingPolicy class =" ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy" >
39+ <fileNamePattern >${LOG_HOME}/error.%d{yyyy-MM-dd}.%i.log</fileNamePattern >
40+ <maxFileSize >10MB</maxFileSize >
41+ <maxHistory >30</maxHistory >
42+ <totalSizeCap >1GB</totalSizeCap >
43+ </rollingPolicy >
44+ <encoder >
45+ <pattern >%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern >
46+ <charset >UTF-8</charset >
47+ </encoder >
48+ </appender >
49+
50+ <!-- 开发环境配置 -->
51+ <springProfile name =" dev" >
52+ <root level =" INFO" >
53+ <appender-ref ref =" CONSOLE" />
54+ <appender-ref ref =" FILE" />
55+ <appender-ref ref =" ERROR_FILE" />
56+ </root >
57+ <logger name =" com.xiaozhi" level =" DEBUG" />
58+ <logger name =" com.xiaozhi.dao" level =" DEBUG" />
59+ <logger name =" com.xiaozhi.websocket" level =" DEBUG" />
60+ <logger name =" org.springframework.web" level =" INFO" />
61+ </springProfile >
62+
63+ <!-- 测试环境配置 -->
64+ <springProfile name =" test" >
65+ <root level =" INFO" >
66+ <appender-ref ref =" CONSOLE" />
67+ <appender-ref ref =" FILE" />
68+ <appender-ref ref =" ERROR_FILE" />
69+ </root >
70+ <logger name =" com.xiaozhi" level =" INFO" />
71+ <logger name =" org.springframework.web" level =" INFO" />
72+ </springProfile >
73+
74+ <!-- 生产环境配置 -->
75+ <springProfile name =" prod" >
76+ <root level =" INFO" >
77+ <appender-ref ref =" FILE" />
78+ <appender-ref ref =" ERROR_FILE" />
79+ <!-- 生产环境通常也保留控制台输出,以便在容器环境中查看日志 -->
80+ <appender-ref ref =" CONSOLE" />
81+ </root >
82+ <logger name =" com.xiaozhi" level =" INFO" />
83+ <logger name =" org.springframework.web" level =" ERROR" />
84+ <logger name =" io.github.imfangs.dify.client.impl.StreamEventDispatcher" level =" ERROR" />
85+ </springProfile >
86+
87+ <!-- 默认配置(如果没有指定profile) -->
88+ <root level =" INFO" >
89+ <appender-ref ref =" CONSOLE" />
90+ <appender-ref ref =" FILE" />
91+ <appender-ref ref =" ERROR_FILE" />
92+ </root >
93+ </configuration >
0 commit comments