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

File Rotation

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

Log files are rotated automatically to prevent uncontrolled file growth and to keep log archives organized and manageable in long-running applications.

Rotation

Rotation is controlled through:

  • MaxFileSize
  • daily file naming

Example configuration:

package main

import (
	"log/slog"

	"github.com/netlifeguru/logger"
)

func main() {
	closer, err := logger.Init(logger.Config{
		Dir:         "./logs",
		MaxFileSize: 10 * 1024 * 1024, // 10MB
	})

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

	defer closer.Close()

	slog.Info("logger started")
}

Generated files

Example output:

logs/
├── 2026-05-11-0001.log
├── 2026-05-11-0002.log
└── 2026-05-12-0001.log

Rotation occurs when:

  • the current file exceeds the configured size limit
  • the current date changes

This provides:

  • predictable file sizes
  • easier log archival
  • simpler debugging by date
  • improved compatibility with log collection systems

The default maximum file size is 10MB

File rotation is performed automatically during writes without requiring manual maintenance or application restarts.

Automatic Log Directory

The logger automatically creates the configured log directory during initialization.

Automatic Cleanup

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

On this page

RotationGenerated files