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
Colorized Terminal OutputSeparate Log LevelsCustom Notice Level
LoggerTerminal Output

Colorized Terminal Output

The logger supports human-readable colored terminal output designed for local development and debugging.

When terminal output is enabled, log entries are printed using ANSI colors based on the log level, making it easier to visually distinguish informational messages, warnings, notices, and errors during runtime.

Enable terminal logging through the TerminalOutput configuration option:

package main

import (
	"log/slog"

	"github.com/netlifeguru/logger"
)

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

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

	defer closer.Close()

	slog.Debug("debug message")
	slog.Info("application started")
	slog.Warn("warning message")
	slog.Error("error message")
}

Example terminal output:

2026-05-11 12:18:13 [DEBUG] debug message
2026-05-11 12:18:13 [INFO] application started
2026-05-11 12:18:13 [WARN] warning message
2026-05-11 12:18:13 [ERROR] error message

Terminal logging is typically enabled during development while production environments primarily rely on structured JSON log files.

Colors can be disabled using:

DisableColors: true

Example file output:

{"time":"2026-05-11T12:18:13.367992+02:00","level":"INFO","msg":"application started"}
{"time":"2026-05-11T12:18:13.368261+02:00","level":"WARN","msg":"warning message"}
{"time":"2026-05-11T12:18:13.36828+02:00","level":"ERROR","msg":"error message"}

This is useful when:

  • logs are redirected to files
  • running inside CI environments
  • terminal output does not support ANSI colors

Configuration

The logger is configured using the `Config` struct.

Separate Log Levels

The logger supports independent log levels for file output and terminal output.