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
Thread Safe DesignOptimized File Writer
LoggerPerformance

Thread Safe Design

The logger is designed for concurrent use and can be safely shared across goroutines.

After initialization, the global slog logger can be used from HTTP handlers, background workers, scheduled jobs, and other concurrent parts of the application without additional synchronization.

Example usage:

package main

import (
	"log/slog"
	"sync"

	"github.com/netlifeguru/logger"
)

func main() {
	closer, err := logger.Init(logger.Config{
		TerminalOutput: true,
	})

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

	defer closer.Close()

	var wg sync.WaitGroup

	for i := 0; i < 5; i++ {
		wg.Add(1)

		go func(workerID int) {
			defer wg.Done()

			slog.Info("worker completed",
				slog.Int("worker_id", workerID),
			)
		}(i)
	}

	wg.Wait()
}

Example terminal output:

2026-05-11 12:54:39 [INFO] worker completed worker_id=0
2026-05-11 12:54:39 [INFO] worker completed worker_id=4
2026-05-11 12:54:39 [INFO] worker completed worker_id=2
2026-05-11 12:54:39 [INFO] worker completed worker_id=1
2026-05-11 12:54:39 [INFO] worker completed worker_id=3

Example file output:

{
  "time": "2026-05-11T12:54:39.74895+02:00",
  "level": "INFO",
  "msg": "worker completed",
  "worker_id": 0
}
{
  "time": "2026-05-11T12:54:39.748946+02:00",
  "level": "INFO",
  "msg": "worker completed",
  "worker_id": 4
}
{
  "time": "2026-05-11T12:54:39.748947+02:00",
  "level": "INFO",
  "msg": "worker completed",
  "worker_id": 2
}
{
  "time": "2026-05-11T12:54:39.749042+02:00",
  "level": "INFO",
  "msg": "worker completed",
  "worker_id": 1
}
{
  "time": "2026-05-11T12:54:39.748997+02:00",
  "level": "INFO",
  "msg": "worker completed",
  "worker_id": 3
}

Thread-safe logging is important for:

  • HTTP servers
  • background workers
  • concurrent jobs
  • message consumers
  • high-load applications

The logger handles concurrent writes internally, so application code does not need to wrap logging calls with mutexes.

Source Tracking

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

Optimized File Writer

The logger includes an optimized file writer designed for high-throughput structured logging.