log

package
v2.6.6 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 17 Imported by: 46

Documentation

Index

Constants

View Source
const (
	LevelNone  = internal.LevelNone
	LevelDebug = internal.LevelDebug
	LevelInfo  = internal.LevelInfo
	LevelWarn  = internal.LevelWarn
	LevelError = internal.LevelError
	LevelFatal = internal.LevelFatal
	LevelPanic = internal.LevelPanic
)

Variables

This section is empty.

Functions

func Close added in v2.1.0

func Close()

Close closes the global logger.

func Debug

func Debug(a ...any)

Debug writes a debug-level log record.

func Debugf

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

Debugf writes a formatted debug-level log record.

func Error

func Error(a ...any)

Error writes an error-level log record.

func Errorf

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

Errorf writes a formatted error-level log record.

func Fatal

func Fatal(a ...any)

Fatal writes a fatal-level log record.

func Fatalf

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

Fatalf writes a formatted fatal-level log record.

func Info

func Info(a ...any)

Info writes an info-level log record.

func Infof

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

Infof writes a formatted info-level log record.

func NewLogger

func NewLogger(opts ...Option) *defaultLogger

NewLogger returns a new logger configured with the given options.

func Panic

func Panic(a ...any)

Panic writes a panic-level log record.

func Panicf

func Panicf(format string, a ...any)

Panicf writes a formatted panic-level log record.

func Print

func Print(level Level, a ...any)

Print writes a log record without stack information.

func Printf

func Printf(level Level, format string, a ...any)

Printf writes a formatted log record without stack information.

func SetLogger

func SetLogger(logger Logger)

SetLogger sets the global logger.

func Warn

func Warn(a ...any)

Warn writes a warn-level log record.

func Warnf

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

Warnf writes a formatted warn-level log record.

Types

type Entity

type Entity = internal.Entity

type Level

type Level = internal.Level

type Logger

type Logger interface {
	slog.Handler
	// Print writes a log record without stack information.
	Print(level Level, a ...any)
	// Printf writes a formatted log record without stack information.
	Printf(level Level, format string, a ...any)
	// Debug writes a debug-level log record.
	Debug(a ...any)
	// Debugf writes a formatted debug-level log record.
	Debugf(format string, a ...any)
	// Info writes an info-level log record.
	Info(a ...any)
	// Infof writes a formatted info-level log record.
	Infof(format string, a ...any)
	// Warn writes a warn-level log record.
	Warn(a ...any)
	// Warnf writes a formatted warn-level log record.
	Warnf(format string, a ...any)
	// Error writes an error-level log record.
	Error(a ...any)
	// Errorf writes a formatted error-level log record.
	Errorf(format string, a ...any)
	// Fatal writes a fatal-level log record.
	Fatal(a ...any)
	// Fatalf writes a formatted fatal-level log record.
	Fatalf(format string, a ...any)
	// Panic writes a panic-level log record.
	Panic(a ...any)
	// Panicf writes a formatted panic-level log record.
	Panicf(format string, a ...any)
	// Close closes the logger.
	Close() error
}

Logger is a logging interface that extends slog.Handler.

func GetLogger

func GetLogger() Logger

GetLogger returns the global logger.

type Option

type Option func(o *options)

Option configures a logger.

func WithCallFullPath added in v2.3.0

func WithCallFullPath(fullPath bool) Option

WithCallFullPath sets whether to emit the full path of the caller file for the stack.

func WithCallSkip added in v2.3.0

func WithCallSkip(skip int) Option

WithCallSkip sets the number of stack frames to skip when emitting the stack.

func WithLevel

func WithLevel(level Level) Option

WithLevel sets the output level of the logger.

func WithStackLevel

func WithStackLevel(level Level) Option

WithStackLevel sets the log level from which the stack is emitted.

func WithSyncers added in v2.3.0

func WithSyncers(syncers ...Syncer) Option

WithSyncers sets the log syncers.

func WithTerminals added in v2.3.0

func WithTerminals[T Terminal | []Terminal | map[Terminal][]Level](terminals ...T) Option

WithTerminals sets the output terminals of the logger.

func WithTimeFormat

func WithTimeFormat(timeFormat string) Option

WithTimeFormat sets the time format of the log output.

type Syncer added in v2.3.0

type Syncer = internal.Syncer

type Terminal added in v2.3.0

type Terminal string

Terminal is a log output terminal.

const (
	TerminalConsole Terminal = "console" // Console terminal
	TerminalFile    Terminal = "file"    // File terminal
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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