feat: add slog structured logging

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
tao.chen
2026-07-02 16:34:42 +08:00
co-authored by Claude Fable 5
parent 8f2f3cf271
commit ea754a85c5
16 changed files with 1432 additions and 82 deletions
+22
View File
@@ -31,6 +31,8 @@ The server listens on `:8080` by default. Override via `configs/config.yaml` or
| `CODESPACE_WRITE_TIMEOUT` | HTTP write timeout (e.g. `15s`) |
| `CODESPACE_IDLE_TIMEOUT` | HTTP idle timeout (e.g. `60s`) |
| `CODESPACE_MAX_HEADER_BYTES` | Max header bytes (e.g. `1048576`) |
| `CODESPACE_LOG_LEVEL` | Log level (`debug`, `info`, `warn`, `error`) |
| `CODESPACE_LOG_FORMAT` | Log format (`json`, `text`) |
## Test
@@ -53,10 +55,30 @@ workspace:
root: "./workspaces"
process:
opencodeCommand: "opencode"
log:
level: "info"
format: "json"
```
The server is started through an explicit `http.Server{Handler: router}` — it does not use `gin.Engine.Run()`.
## Logging
codespace uses the Go standard library `log/slog` for application logs. Default output is JSON to stdout.
```yaml
log:
level: "info"
format: "json"
```
Environment overrides:
- `CODESPACE_LOG_LEVEL` (`debug`, `info`, `warn`, `error`)
- `CODESPACE_LOG_FORMAT` (`json`, `text`)
All application logs must go through `log/slog`. Do not use `fmt.Print*`, `log.Printf`, `gin.Logger()`, or third-party logging libraries in server runtime code.
## API examples
Health check: