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>
This commit is contained in:
2026-06-29 18:01:08 -07:00
parent 7fcb19ad49
commit 626e1bb5ac
9 changed files with 258 additions and 149 deletions
+37 -2
View File
@@ -1,5 +1,40 @@
# applog
applog is a opinionated logger configuration.
Opinionated slog wiring for go-toolkit [app](https://gitea.auvem.com/go-toolkit/app) lifecycles.
WARNING: do not use this library, the API is not stable and I make breaking changes at random. There's a reason it's not on GitHub yet, or possibly ever tbh.
## 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` |