log

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package log provides leveled logging matching Microsoft LogLevel semantics.

Levels (ascending severity):

Trace (0) — most verbose, diagnostic detail
Debug (1) — debugging info
Info  (2) — general operational messages
Warn  (3) — non-critical issues
Error (4) — runtime errors
Fatal (5) — critical failures, process exiting
Off   (6) — nothing logged

Index

Constants

This section is empty.

Variables

View Source
var Default = New(os.Stderr, Info)

Default logger at Info level writing to stderr.

Functions

func Debugf

func Debugf(format string, args ...any)

func Errorf

func Errorf(format string, args ...any)

func Fatalf

func Fatalf(format string, args ...any)

func Infof

func Infof(format string, args ...any)

func Tracef

func Tracef(format string, args ...any)

Convenience wrappers for Default logger.

func Warnf

func Warnf(format string, args ...any)

Types

type Level

type Level int

Level is a logging severity level.

const (
	Trace Level = iota // 0: most verbose
	Debug              // 1
	Info               // 2
	Warn               // 3
	Error              // 4
	Fatal              // 5: critical, process exiting
	Off                // 6: nothing logged
)

func ParseLevel

func ParseLevel(s string) (Level, error)

ParseLevel converts a string to Level. Accepts: trace, debug, info, warn, error, fatal, off (case-insensitive).

type Logger

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

Logger is a leveled logger.

func New

func New(w io.Writer, level Level) *Logger

New creates a Logger that writes to w. Default level is Info.

func (*Logger) Debug

func (l *Logger) Debug(format string, args ...any)

Debug logs at Debug level.

func (*Logger) Error

func (l *Logger) Error(format string, args ...any)

Error logs at Error level.

func (*Logger) Fatal

func (l *Logger) Fatal(format string, args ...any)

Fatal logs at Fatal level then exits with code 1.

func (*Logger) Info

func (l *Logger) Info(format string, args ...any)

Info logs at Info level.

func (*Logger) Level

func (l *Logger) Level() Level

Level returns the current minimum level.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

SetLevel changes the minimum level.

func (*Logger) Trace

func (l *Logger) Trace(format string, args ...any)

Trace logs at Trace level.

func (*Logger) Warn

func (l *Logger) Warn(format string, args ...any)

Warn logs at Warn level.

Jump to

Keyboard shortcuts

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