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

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.

Daily Log Naming

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

Standard Compatible

Next Page