log

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package log provides a structured, leveled logging abstraction.

It defines a Logger interface with Debug, Info, Warn, and Error methods. Two implementations are provided:

  • StdLogger: writes to an io.Writer with configurable level filtering and text or JSON output format.
  • nopLogger: a zero-allocation no-op logger for when logging is disabled.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Format

type Format int

Format controls the output format of the logger.

const (
	// FormatText outputs human-readable text lines.
	FormatText Format = iota
	// FormatJSON outputs one JSON object per line.
	FormatJSON
)

type Level

type Level int

Level represents a log severity level.

const (
	// LevelDebug is the most verbose level.
	LevelDebug Level = iota
	// LevelInfo is for general operational messages.
	LevelInfo
	// LevelWarn is for warning conditions.
	LevelWarn
	// LevelError is for error conditions.
	LevelError
)

func (Level) String

func (l Level) String() string

String returns the human-readable name of a log level.

type Logger

type Logger interface {
	// Debug logs a message at DEBUG level.
	Debug(msg string, fields ...string)
	// Info logs a message at INFO level.
	Info(msg string, fields ...string)
	// Warn logs a message at WARN level.
	Warn(msg string, fields ...string)
	// Error logs a message at ERROR level.
	Error(msg string, fields ...string)
	// WithLevel returns a new Logger with the given minimum level.
	WithLevel(level Level) Logger
}

Logger is the interface for structured, leveled logging. Each method accepts a message and optional key-value pairs. Keys and values are provided as alternating string arguments.

func Nop

func Nop() Logger

Nop returns a Logger that discards all log output with zero allocation.

type StdLogger

type StdLogger struct {
	// contains filtered or unexported fields
}

StdLogger writes structured log entries to an io.Writer.

func New

func New(w io.Writer, level Level, format Format) *StdLogger

New creates a new StdLogger writing to w at the given minimum level and output format.

func (*StdLogger) Debug

func (l *StdLogger) Debug(msg string, fields ...string)

Debug logs at DEBUG level.

func (*StdLogger) Error

func (l *StdLogger) Error(msg string, fields ...string)

Error logs at ERROR level.

func (*StdLogger) Info

func (l *StdLogger) Info(msg string, fields ...string)

Info logs at INFO level.

func (*StdLogger) Warn

func (l *StdLogger) Warn(msg string, fields ...string)

Warn logs at WARN level.

func (*StdLogger) WithLevel

func (l *StdLogger) WithLevel(level Level) Logger

WithLevel returns a new StdLogger sharing the same writer but with a different minimum log level.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL