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>
1.8 KiB
1.8 KiB
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
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:
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
- Rotation: When the current log file exceeds
MaxSize, it is rotated. The current file is renamed tofilename.1,filename.1is renamed tofilename.2, and so on. - Retention:
- Files beyond
MaxBackupsare automatically deleted during rotation. - Files older than
MaxAgedays are automatically deleted during the cleanup process.
- Files beyond
- Appends: When an application restarts, it appends to the existing log file instead of truncating it.