go/docs/pkg/log.md
Snider f71f4c7d66 docs: remove stale CLI/ecosystem docs, keep framework-only content
Massive cleanup after module extraction sprint. core/go is now a pure
DI framework — docs should reflect that, not document CLI commands.

- Delete 130+ CLI command/example docs (already in core/cli)
- Delete 6 obsolete pkg-batch*-analysis.md files
- Delete plans/, skill/, static/, mcp/ (moved to correct repos)
- Rewrite index.md for DI framework (not CLI)
- Fix PACKAGE_STANDARDS.md: framework.* → core.* references
- Fix log.md: correct framework integration example

Remaining docs: index.md, pkg/PACKAGE_STANDARDS.md, pkg/log.md

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-06 14:24:35 +00:00

55 lines
1.8 KiB
Markdown

# Log Retention Policy
The `log` package provides structured logging with automatic log rotation and retention management.
## Retention Policy
By default, the following log retention policy is applied when log rotation is enabled:
- **Max Size**: 100 MB per log file.
- **Max Backups**: 5 old log files are retained.
- **Max Age**: 28 days. Old log files beyond this age are automatically deleted. (Set to -1 to disable age-based retention).
- **Compression**: Rotated log files can be compressed (future feature).
## Configuration
Logging can be configured using the `log.Options` struct. To enable log rotation to a file, provide a `RotationOptions` struct. If both `Output` and `Rotation` are provided, `Rotation` takes precedence and `Output` is ignored.
### Standalone Usage
```go
logger := log.New(log.Options{
Level: log.LevelInfo,
Rotation: &log.RotationOptions{
Filename: "app.log",
MaxSize: 100, // MB
MaxBackups: 5,
MaxAge: 28, // days
},
})
logger.Info("application started")
```
### Framework Integration
When using the Core framework, logging is usually configured during application initialization:
```go
app, _ := core.New(
core.WithName("log", log.NewService(log.Options{
Level: log.LevelDebug,
Rotation: &log.RotationOptions{
Filename: "/var/log/my-app.log",
},
})),
)
```
## How It Works
1. **Rotation**: When the current log file exceeds `MaxSize`, it is rotated. The current file is renamed to `filename.1`, `filename.1` is renamed to `filename.2`, and so on.
2. **Retention**:
- Files beyond `MaxBackups` are automatically deleted during rotation.
- Files older than `MaxAge` days are automatically deleted during the cleanup process.
3. **Appends**: When an application restarts, it appends to the existing log file instead of truncating it.