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

Context Logging

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

Context logging is useful for propagating request-scoped or operation-scoped information across HTTP handlers, background workers, database operations, and distributed services.

Supported methods include:

  • InfoContext: Logs informational messages with context propagation
  • WarnContext: Logs warning messages related to recoverable or unexpected situations
  • ErrorContext: Logs errors and failure-related events with contextual information
  • DebugContext: Logs detailed debugging information useful during development
  • NoticeContext: Logs important operational events intended to remain highly visible

Example usage:

package main

import (
	"context"
	"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()

	ctx := context.Background()

	slog.InfoContext(ctx, "request started")
	slog.WarnContext(ctx, "slow database query")
	logger.NoticeContext(ctx, "background sync completed")
}

Example output:

{
  "time": "2026-05-11T12:50:26.854582+02:00",
  "level": "INFO",
  "msg": "request started"
}
{
  "time": "2026-05-11T12:50:26.855051+02:00",
  "level": "WARN",
  "msg": "slow database query"
}

Context-aware logging helps:

  • propagate request lifecycle information
  • correlate logs across operations
  • integrate with tracing systems
  • support middleware-driven architectures
  • improve observability in concurrent applications

Because the logger is fully compatible with log/slog, existing slog context-based workflows continue to work without modification.

Standard Compatible

Previous Page

Structured Chaining

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