moki 2 недель назад
Родитель
Сommit
f6b42df8c2
5 измененных файлов с 42 добавлено и 7 удалено
  1. 2 2
      README.md
  2. 2 0
      cmd/monitor/main.go
  3. 36 3
      docs/api.md
  4. 1 1
      internal/api/api.go
  5. 1 1
      internal/event/event.go

+ 2 - 2
README.md

@@ -116,7 +116,7 @@ curl http://localhost:8080/api/mqtt
 ```json
 {
   "port": 4096,
-  "status": "忙碌",
+  "status": "工作中",
   "code": "busy",
   "timestamp": "2026-06-03T14:30:00Z"
 }
@@ -127,7 +127,7 @@ curl http://localhost:8080/api/mqtt
 | status | code | 说明 |
 |--------|------|------|
 | 空闲 | idle | 会话空闲 |
-| 忙碌 | busy | 会话忙碌 |
+| 工作中 | busy | 会话工作中 |
 | 重试中 | retry | 会话重试中 |
 | 修改中 | pending | 会话修改中 |
 | 思考中 | reasoning | 模型推理中 |

+ 2 - 0
cmd/monitor/main.go

@@ -344,6 +344,8 @@ func printConfigUsage() {
 	fmt.Println("  --topic           MQTT 主题")
 	fmt.Println("  --enabled         是否启用 (true/false)")
 	fmt.Println("  --db              数据库路径")
+	fmt.Println("  --log-file        日志文件路径(默认 ./logs/monitor.log)")
+	fmt.Println("  --log-level       日志级别 (debug/info/warn/error)")
 }
 
 func createCallback(mqttClient *mqttcli.Client, apiServer *api.Server) monitor.EventCallback {

+ 36 - 3
docs/api.md

@@ -198,6 +198,39 @@ DELETE /api/mqtt/:id
 ./bin/opencode-monitor monitor --ports 4096 --api-addr :8080
 ```
 
+## 全局选项
+
+以下选项适用于 `monitor`、`serve`、`config` 三个子命令:
+
+| 选项 | 默认值 | 说明 |
+|------|--------|------|
+| `--log-file` | `./logs` | 日志文件路径。默认 `./logs/monitor.log`,按天自动轮转,同时输出到控制台和文件 |
+| `--log-level` | `info` | 日志级别:`debug`、`info`、`warn`、`error` |
+
+### 日志示例
+
+```bash
+# 默认日志到 ./logs/monitor.log
+./bin/opencode-monitor monitor --ports 4096
+
+# 指定日志路径
+./bin/opencode-monitor serve --log-file /var/log/monitor.log
+
+# 开启 debug 日志
+./bin/opencode-monitor monitor --scan 4096-4100 --log-level debug
+```
+
+### 日志文件轮转
+
+日志按天自动轮转,跨天后旧文件自动重命名:
+
+```
+logs/
+├── monitor.log           # 当天日志
+├── monitor.log.2026-06-03  # 历史日志
+└── monitor.log.2026-06-02  # 历史日志
+```
+
 ## CORS
 
 API 已启用 CORS,支持跨域请求。
@@ -209,7 +242,7 @@ API 已启用 CORS,支持跨域请求。
 ```json
 {
   "port": 4096,
-  "status": "忙碌",
+  "status": "工作中",
   "code": "busy",
   "timestamp": "2026-06-03T14:30:00Z"
 }
@@ -220,7 +253,7 @@ API 已启用 CORS,支持跨域请求。
 | status | code | 说明 |
 |--------|------|------|
 | 空闲 | idle | 会话空闲 |
-| 忙碌 | busy | 会话忙碌 |
+| 工作中 | busy | 会话工作中 |
 | 重试中 | retry | 会话重试中 |
 | 修改中 | pending | 会话修改中 |
 | 思考中 | reasoning | 模型推理中 |
@@ -249,7 +282,7 @@ WebSocket 推送的消息格式为 JSON:
 ```json
 {
   "port": 4096,
-  "status": "忙碌",
+  "status": "工作中",
   "code": "busy",
   "timestamp": "2026-06-03T14:30:00Z"
 }

+ 1 - 1
internal/api/api.go

@@ -316,7 +316,7 @@ func (s *Server) handleIndex(w http.ResponseWriter, r *http.Request) {
         .status-value { font-size: 32px; font-weight: bold; margin-bottom: 8px; }
         .status-time { color: #999; font-size: 12px; }
         .status-空闲 { color: #52c41a; }
-        .status-忙碌 { color: #ff4d4f; }
+        .status-工作中 { color: #ff4d4f; }
         .status-思考中 { color: #faad14; }
         .status-运行中 { color: #1890ff; }
         .status-完成 { color: #52c41a; }

+ 1 - 1
internal/event/event.go

@@ -25,7 +25,7 @@ func ParseStatus(status map[string]interface{}) string {
 	case "idle":
 		return "空闲"
 	case "busy":
-		return "忙碌"
+		return "工作中"
 	case "retry":
 		return "重试中"
 	case "pending":