LoggerFile Rotation
Graceful Shutdown
The logger returns a `Closer` instance during initialization to ensure that file handles and internal resources are released properly when the application exits.
Closing the logger is important for:
- flushing pending writes
- closing active file descriptors
- finalizing rotated log files
- ensuring clean application shutdown
Example usage:
package main
import (
"log/slog"
"github.com/netlifeguru/logger"
)
func main() {
closer, err := logger.Init(logger.Config{
TerminalOutput: true,
})
if err != nil {
slog.Error(err.Error())
return
}
defer closer.Close()
slog.Info("application started")
}Using defer closer.Close() immediately after initialization is the recommended pattern.
This guarantees that the logger is closed correctly even if the application exits due to an error or early return.
The shutdown process is safe for concurrent applications and integrates naturally with standard Go application lifecycle patterns.