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
InstallationQuick StartConfiguration
LoggerGetting Started

Configuration

The logger is configured using the `Config` struct.

  • Dir string: Directory for log files. Defaults to ./logs.
  • TerminalOutput bool: Enables or disables console output.
  • MinLevel slog.Level: Minimum level for file logging. Defaults to slog.LevelInfo.
  • ConsoleMinLevel slog.Level: Minimum level specifically for console output. If not set, it follows MinLevel.
  • MaxFileSize int64: Maximum size per log file before rotation. Defaults to 10MB.
  • MaxLogFiles int: Maximum number of managed log files to keep. Defaults to 5.
  • DisableColors bool: Disables ANSI colors in console output.
  • AddSource bool: Adds source file and line information to structured log output.
type Config struct {
    Dir             string
    TerminalOutput  bool
    MinLevel        slog.Level
    ConsoleMinLevel slog.Level
    MaxFileSize     int64
    MaxLogFiles     int
    DisableColors   bool
    AddSource       bool
}

Dir

Directory where log files are stored.

If the directory does not exist, it is created automatically during logger initialization.

Default directory:

./logs

TerminalOutput

Enables or disables terminal logging. When enabled, logs are written both to files and to the console using a human-readable colored format. Typical usage:

  • enabled during local development
  • disabled in production containers

MinLevel

Defines the minimum log level written to log files. Example:

MinLevel: slog.LevelInfo

This means:

  • INFO
  • WARN
  • ERROR

are written to files, while lower levels such as DEBUG are ignored.

ConsoleMinLevel

Defines the minimum log level used specifically for terminal output.

This allows terminal logging to be more or less verbose independently of file logging.

Example:

MinLevel: slog.LevelInfo
ConsoleMinLevel: slog.LevelDebug

In this configuration:

  • files store only INFO and above
  • terminal output also includes DEBUG

If not set, the console uses the same level as MinLevel.

MaxFileSize

Maximum size of a single log file before automatic rotation occurs.

Example:

MaxFileSize: 10 * 1024 * 1024

Default:

10MB

When the limit is reached, the logger automatically creates a new file.

MaxLogFiles

Maximum number of rotated log files kept on disk.

Older files are removed automatically during cleanup.

Example:

MaxLogFiles: 5

DisableColors

Disables ANSI terminal colors.

Useful when:

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

AddSource

Adds source file and line information to log entries.

Example output:

{
  "source": {
    "function": "main.main",
    "file": "/examples/add_source/main.go",
    "line": 19
  }
}

Useful during development and debugging, but may slightly increase logging overhead.

The configuration system is designed to remain fully compatible with Go’s standard log/slog ecosystem while providing production-oriented logging features such as rotation, structured output, and terminal formatting.

Quick Start

Previous Page

Colorized Terminal Output

Next Page

On this page

DirTerminalOutputMinLevelConsoleMinLevelMaxFileSizeMaxLogFilesDisableColorsAddSource