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
Structured JSON Logging
LoggerJSON Logging

Structured JSON Logging

The logger writes structured log entries as JSON, making logs easy to parse, search, and process in production environments.

Each log entry is stored as a single JSON object containing standardized fields such as timestamp, level, and message.

Example log entry:

{
  "time": "2026-05-11T11:08:42.135294+02:00",
  "level": "INFO",
  "msg": "server started"
}

JSON logging is enabled automatically when file logging is active.

package main

import (
	"log/slog"

	"github.com/netlifeguru/logger"
)

func main() {
	closer, err := logger.Init(logger.Config{
		Dir:      "./logs",
		MinLevel: slog.LevelInfo,
	})

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

	defer closer.Close()

	slog.Info("server started")
	slog.Warn("high memory usage")
	slog.Error("database connection failed")
}

Generated log file:

logs/2026-05-11-0001.log

Structured JSON logs are useful for:

  • centralized log aggregation
  • observability platforms
  • production monitoring
  • analytics pipelines
  • machine parsing and indexing

Additional structured fields can be attached directly through the standard slog API:

slog.Info("user authenticated",
slog.Int("user_id", 42),
slog.String("role", "admin"),
)

File output:

{
  "time": "2026-05-11T12:23:38.592038+02:00",
  "level": "INFO",
  "msg": "user authenticated",
  "user_id": 42,
  "role": "admin"
}

Terminal output

2026-05-11 12:23:38 [INFO] user authenticated user_id=42 role=admin

Custom Notice Level

The logger includes a custom `LevelNotice` log level designed for important operational messages that should remain highly visible in terminal output.

Automatic Log Directory

The logger automatically creates the configured log directory during initialization.