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
Standard CompatibleContext LoggingStructured ChainingSource Tracking
LoggerStructured Logging

Standard Compatible

logger is built directly on top of Go’s standard log/slog package.

After initialization, the logger automatically registers itself as the global slog logger, allowing the application to continue using the standard logging API without introducing a custom logging interface.

This keeps the package fully compatible with existing Go logging patterns while extending slog with structured file logging, terminal output, file rotation, and additional helper functionality.

package main

import (
	"log/slog"

	"github.com/netlifeguru/logger"
)

func main() {
	closer, err := logger.Init(logger.Config{
		Dir:             "./logs",
		TerminalOutput:  true,
		DisableColors:   false,
		MinLevel:        slog.LevelInfo,
		ConsoleMinLevel: slog.LevelDebug,
		MaxFileSize:     10 * 1024 * 1024,
		MaxLogFiles:     5,
		AddSource:       true,
	})

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

	defer closer.Close()

	slog.Info("logger initialized")
}

Once initialized, all standard logging methods such as slog.Info, slog.Warn, and slog.Error automatically use the configured logger instance.

The example above enables:

  • structured JSON file logging
  • colorized terminal output
  • source location tracking
  • automatic log rotation
  • automatic cleanup of old log files

while remaining fully compatible with the standard Go logging ecosystem.

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.

Context Logging

The logger supports context-aware logging through the standard `context.Context` integration provided by `log/slog`.