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

Structured Chaining

The logger supports reusable structured loggers through `logger.With(...)` and the standard `slog` attribute system.

Structured chaining allows applications to attach shared metadata once and automatically include it in all subsequent log entries produced by that logger instance.

This is useful for:

  • request-scoped logging
  • service-specific loggers
  • worker identifiers
  • module separation
  • tenant or user tracking

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())
	}

	defer closer.Close()

	apiLogger := slog.With(
		slog.String("service", "api"),
		slog.String("version", "v1"),
	)

	apiLogger.Info("server started")

	userLogger := apiLogger.With(
		slog.Int("user_id", 42),
	)

	userLogger.Info("user authenticated")
}

Example output:

2026-05-11 12:51:26 [INFO] server started service=api version=v1
2026-05-11 12:51:26 [INFO] user authenticated service=api version=v1 user_id=42

Example file output:

{
  "time": "2026-05-11T12:52:05.952406+02:00",
  "level": "INFO",
  "msg": "server started",
  "service": "api",
  "version": "v1"
}
{
  "time": "2026-05-11T12:52:05.953044+02:00",
  "level": "INFO",
  "msg": "user authenticated",
  "service": "api",
  "version": "v1",
  "user_id": 42
}

Attributes added through chained loggers are inherited automatically, making it easy to build hierarchical structured logging pipelines without repeating common metadata.

Context Logging

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

Source Tracking

The logger can include source file and line information in log entries.