LoggerFile Rotation
Automatic Log Directory
The logger automatically creates the configured log directory during initialization.
This removes the need to manually create directories before starting the application and ensures that log files can be written immediately after the logger is initialized.
By default, logs are stored in:
./logsCustom directories can be configured using the Dir option:
package main
import (
"log/slog"
"github.com/netlifeguru/logger"
)
func main() {
closer, err := logger.Init(logger.Config{
Dir: "./storage/logs",
})
if err != nil {
slog.Error(err.Error())
}
defer closer.Close()
slog.Info("logger initialized")
}Example generated structure:
storage/
└── logs/
└── 2026-05-11-0001.logThis behavior is especially useful for:
- fresh deployments
- containerized environments
- CI/CD pipelines
- ephemeral infrastructure
- automated server provisioning