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:
ryan
2026-03-13 14:53:51 +08:00
parent 06d4831d55
commit aeb7118b30
17 changed files with 321 additions and 209 deletions
+33 -29
View File
@@ -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
```
---