mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-30 14:26:36 +08:00
Refactor logging to use slog package across the application
- Replaced standard log package with log/slog in httpclient, nginx manager, sync service, updater, and other components for structured logging. - Introduced environment variable `LOG_LEVEL` to control logging levels (debug, info, warn, error). - Updated documentation to reflect changes in logging configuration and requirements. - Added a new logging setup function in the ats_agent internal package to initialize the slog logger.
This commit is contained in:
+16
-3
@@ -188,9 +188,22 @@ Agent 当前支持两类启动配置:
|
||||
1. 命令行参数
|
||||
2. `agent.json` 配置文件
|
||||
|
||||
当前 Agent **没有额外环境变量作为正式配置入口**,启动行为主要由 `-config` 参数和配置文件字段决定。
|
||||
|
||||
### 2.1 Agent 命令行参数
|
||||
当前 Agent 仅支持少量环境变量用于日志输出控制;核心启动行为仍由 `-config` 参数和配置文件字段决定。
|
||||
|
||||
### 2.1.1 Agent 环境变量
|
||||
|
||||
支持的环境变量:
|
||||
|
||||
| 环境变量 | 作用 | 默认值 | 示例 |
|
||||
| --- | --- | --- | --- |
|
||||
| `LOG_LEVEL` | 指定 Agent 的 `slog` 日志等级;支持 `debug`/`info`/`warn`/`error`(`warning` 兼容为 `warn`) | `info` | `LOG_LEVEL=debug` |
|
||||
|
||||
说明:
|
||||
|
||||
* `LOG_LEVEL` 只影响 Agent 本地日志输出,不改变心跳、同步或配置行为
|
||||
* 未设置或设置为不支持的值时,将回退为 `info`
|
||||
|
||||
### 2.1 Agent 命令行参数
|
||||
|
||||
启动示例:
|
||||
|
||||
|
||||
+33
-29
@@ -6,18 +6,18 @@
|
||||
|
||||
## 1. 前置条件
|
||||
|
||||
### 1.1 Server
|
||||
### 1.1 Server
|
||||
|
||||
* Go 1.23+
|
||||
* Node.js 18+
|
||||
* 可写 SQLite 文件目录
|
||||
|
||||
* Go 1.18+
|
||||
* Node.js 18+
|
||||
* 可写 SQLite 文件目录
|
||||
|
||||
### 1.2 Agent
|
||||
|
||||
* Go 1.18+
|
||||
* 对 Agent 数据目录有写权限
|
||||
* 若使用独立 OpenResty 模式:可执行 `openresty -t` 与 `openresty -s reload`
|
||||
* 若使用 Docker 模式:具备 Docker 执行权限
|
||||
### 1.2 Agent
|
||||
|
||||
* Go 1.23+
|
||||
* 对 Agent 数据目录有写权限
|
||||
* 若使用独立 OpenResty 模式:可执行 `openresty -t` 与 `openresty -s reload`
|
||||
* 若使用 Docker 模式:具备 Docker 执行权限
|
||||
* 第五版主配置接管模式下,Agent 对 OpenResty 主配置目标路径必须具备写权限
|
||||
|
||||
---
|
||||
@@ -41,18 +41,20 @@ pnpm build
|
||||
|
||||
### 2.2 启动服务
|
||||
|
||||
```bash
|
||||
cd atsf_server
|
||||
export SESSION_SECRET='replace-with-random-string'
|
||||
export SQLITE_PATH='./atsflare.db'
|
||||
go run .
|
||||
```
|
||||
```bash
|
||||
cd atsf_server
|
||||
export SESSION_SECRET='replace-with-random-string'
|
||||
export SQLITE_PATH='./atsflare.db'
|
||||
export LOG_LEVEL='info'
|
||||
go run .
|
||||
```
|
||||
|
||||
说明:
|
||||
|
||||
* 默认不依赖全局 `AGENT_TOKEN`
|
||||
* 节点接入凭证由数据库维护:节点专属 `agent_token` + 全局 `discovery_token`
|
||||
* 默认监听端口为 `3000`
|
||||
* 默认不依赖全局 `AGENT_TOKEN`
|
||||
* 节点接入凭证由数据库维护:节点专属 `agent_token` + 全局 `discovery_token`
|
||||
* 默认监听端口为 `3000`
|
||||
* `LOG_LEVEL` 支持 `debug` / `info` / `warn` / `error`
|
||||
|
||||
### 2.3 使用 docker-compose 启动 Server
|
||||
|
||||
@@ -196,18 +198,20 @@ swag init -g main.go -o docs
|
||||
|
||||
### 4.1 直接运行
|
||||
|
||||
```bash
|
||||
cd atsf_agent
|
||||
go run ./cmd/agent -config /path/to/agent.json
|
||||
```
|
||||
```bash
|
||||
cd atsf_agent
|
||||
export LOG_LEVEL='info'
|
||||
go run ./cmd/agent -config /path/to/agent.json
|
||||
```
|
||||
|
||||
### 4.2 编译后二进制运行
|
||||
|
||||
```bash
|
||||
cd atsf_agent
|
||||
go build -o atsflare-agent ./cmd/agent
|
||||
./atsflare-agent -config /path/to/agent.json
|
||||
```
|
||||
```bash
|
||||
cd atsf_agent
|
||||
go build -o atsflare-agent ./cmd/agent
|
||||
export LOG_LEVEL='info'
|
||||
./atsflare-agent -config /path/to/agent.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
`atsf_server` 继续作为单体控制面:
|
||||
|
||||
* Go 1.23+
|
||||
* Gin
|
||||
* GORM
|
||||
* SQLite
|
||||
@@ -36,6 +37,7 @@
|
||||
|
||||
`atsf_agent` 继续作为 Go 单体程序:
|
||||
|
||||
* Go 1.23+
|
||||
* 单二进制
|
||||
* 节点本地执行
|
||||
* `openresty_path` 优先
|
||||
@@ -275,6 +277,7 @@ Agent 必须满足:
|
||||
|
||||
要求:
|
||||
|
||||
* Server 与 Agent 统一使用 `slog` 输出结构化日志
|
||||
* 日志足够定位问题
|
||||
* 不打印敏感凭证完整值
|
||||
|
||||
|
||||
Reference in New Issue
Block a user