NetLife Guru

Open source Go packages for fast, maintainable web systems. Built with a documentation-first approach.

Product
OverviewGolang packagesNews
Documentation
DocumentationGo LoggerGo RouterGo DB Form
Company
OverviewContactNewsGitHub
Community / Support
Supportinfo@netlife.guru
© 2026 NetLife Guru. All rights reserved.
GitHubinfo@netlife.guru
NetLife GuruNetLife GuruNetLife Guru
NetLife GuruNetLife GuruNetLife Guru
OverviewDocumentationNewsSupportContact

Golang packages

Logger Introduction
Automatic Log DirectoryFile RotationAutomatic CleanupDaily Log NamingGraceful Shutdown
LoggerFile Rotation

Automatic Cleanup

The logger automatically removes old rotated log files to prevent uncontrolled disk usage.

Cleanup behavior is controlled through the MaxLogFiles configuration option, which defines the maximum number of managed log files kept on disk.

Example configuration:

package main

import (
	"log/slog"

	"github.com/netlifeguru/logger"
)

func main() {
	closer, err := logger.Init(logger.Config{
		Dir:         "./logs",
		MaxLogFiles: 5,
	})

	if err != nil {
		slog.Error(err.Error())
	}

	defer closer.Close()

	slog.Info("logger initialized")
}

Example directory before cleanup:

logs/
├── 2026-05-08-0001.log
├── 2026-05-09-0001.log
├── 2026-05-10-0001.log
├── 2026-05-11-0001.log
├── 2026-05-11-0002.log
├── 2026-05-11-0003.log
└── 2026-05-11-0004.log

After cleanup:

logs/
├── 2026-05-10-0001.log
├── 2026-05-11-0001.log
├── 2026-05-11-0002.log
├── 2026-05-11-0003.log
└── 2026-05-11-0004.log

Cleanup runs automatically during log rotation and removes the oldest managed log files first.

This helps:

  • reduce disk usage
  • simplify maintenance
  • avoid oversized log directories
  • keep deployments predictable over time

Default value:

MaxLogFiles: 5

File Rotation

The logger supports automatic file rotation based on both date and file size.

Daily Log Naming

The logger uses date-based file naming to organize log output by day and rotation sequence.