LoggerPerformance
Optimized File Writer
The logger includes an optimized file writer designed for high-throughput structured logging.
File writes are handled efficiently to reduce allocation overhead and keep logging predictable even in busy applications.
This is especially useful for:
- HTTP APIs
- background workers
- queue consumers
- long-running services
- applications with frequent structured logs
Example usage:
package main
import (
"log/slog"
"github.com/netlifeguru/logger"
)
func main() {
closer, err := logger.Init(logger.Config{
Dir: "./logs",
TerminalOutput: false,
MinLevel: slog.LevelInfo,
})
if err != nil {
slog.Error(err.Error())
}
defer closer.Close()
slog.Info("file logging enabled",
slog.String("service", "api"),
slog.String("environment", "production"),
)
}Example file output:
{
"time": "2026-05-11T12:56:31.879333+02:00",
"level": "INFO",
"msg": "file logging enabled",
"service": "api",
"environment": "production"
}The file writer is optimized for:
- structured JSON output
- repeated log writes
- concurrent application workloads
- reduced allocation overhead
- predictable file rotation behavior
For applications where logging is part of a hot path, this keeps persisted logs useful without introducing unnecessary runtime pressure.