Files
applog/README.md
T
end 626e1bb5ac fix: lifecycle-safe logger teardown without global state
Store file handle per module, swap lifecycle logger before closing file,
return teardown errors, remove duplicate Module() func.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-29 18:01:08 -07:00

41 lines
1007 B
Markdown

# applog
Opinionated slog wiring for go-toolkit [app](https://gitea.auvem.com/go-toolkit/app) lifecycles.
## Install
```bash
go get gitea.auvem.com/go-toolkit/applog
```
## Usage
```go
lifecycle := app.NewLifecycle(applog.AppLogOpts{
ConsoleOutput: os.Stderr,
ConsoleLevel: slog.LevelInfo,
FileOutput: "/var/log/myapp.log",
FileLevel: slog.LevelInfo,
}.Module())
```
## Outputs
| Sink | Format | Default level |
|------|--------|---------------|
| Console (`ConsoleOutput`) | tint (human-readable) | Info |
| File (`FileOutput`) | JSON lines | Info |
## Teardown
On teardown the log file is closed and the lifecycle logger falls back to console-only (or discard). Logging via `lifecycle.Logger()` after teardown does not write to a closed file.
## Migration from pre-V1 API
| Before | After |
|--------|-------|
| `applog.Module(opts)` | `opts.Module()` |
| `LogOutput` | `ConsoleOutput` |
| `LogFile` | `FileOutput` |
| `Verbose bool` | `ConsoleLevel: slog.LevelDebug` |