626e1bb5ac
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>
41 lines
1007 B
Markdown
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` |
|