log

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 6 Imported by: 28

Documentation

Index

Constants

View Source
const (
	// LevelDebug level. Usually only enabled when debugging. Very verbose logging.
	LevelDebug = Level(slog.LevelDebug) // -4
	// LevelInfo level. General operational entries about what's going on inside the application.
	LevelInfo = Level(slog.LevelInfo) // 0
	// LevelWarning level. Non-critical entries that deserve eyes.
	LevelWarning = Level(slog.LevelWarn) // 4
	// LevelError level. Used for errors that should definitely be noted.
	LevelError = Level(slog.LevelError) // 8
	// LevelFatal level. Logs and then calls `os.Exit(1)`.
	LevelFatal = Level(slog.LevelError + 4) // 12
	// LevelPanic level. Highest level of severity. Logs and then calls panic.
	LevelPanic = Level(slog.LevelError + 8) // 16
)
View Source
const (
	// DebugLevel is an alias for LevelDebug level.
	// Deprecated: use LevelDebug instead, DebugLevel will be removed in v1.18.
	DebugLevel = LevelDebug
	// InfoLevel is an alias for LevelInfo level.
	// Deprecated: use LevelInfo instead, InfoLevel will be removed in v1.18.
	InfoLevel = LevelInfo
	// WarningLevel is an alias for LevelWarning level.
	// Deprecated: use LevelWarning instead, WarningLevel will be removed in v1.18.
	WarningLevel = LevelWarning
	// ErrorLevel is an alias for LevelError level.
	// Deprecated: use LevelError instead, ErrorLevel will be removed in v1.18.
	ErrorLevel = LevelError
	// FatalLevel is an alias for LevelFatal level.
	// Deprecated: use LevelFatal instead, FatalLevel will be removed in v1.18.
	FatalLevel = LevelFatal
	// PanicLevel is an alias for LevelPanic level.
	// Deprecated: use LevelPanic instead, PanicLevel will be removed in v1.18.
	PanicLevel = LevelPanic
)
View Source
const (
	DriverStack  = "stack"
	DriverSingle = "single"
	DriverDaily  = "daily"
	DriverOtel   = "otel"
	DriverCustom = "custom"
)
View Source
const (
	// Deprecated: use DriverStack instead, StackDriver will be removed in v1.18.
	StackDriver = DriverStack
	// Deprecated: use DriverSingle instead, SingleDriver will be removed in v1.18.
	SingleDriver = DriverSingle
	// Deprecated: use DriverDaily instead, DriverDaily will be removed in v1.18.
	DailyDriver = DriverDaily
	// Deprecated: use DriverCustom instead, CustomDriver will be removed in v1.18.
	CustomDriver = DriverCustom
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Data added in v1.14.9

type Data map[string]any

type Entry added in v1.0.0

type Entry interface {
	// Code returns the associated code.
	Code() string
	// Context returns the context of the entry.
	Context() context.Context
	// Data returns the data of the entry.
	Data() Data
	// Domain returns the domain of the entry.
	Domain() string
	// Hint returns the hint of the entry.
	Hint() string
	// Level returns the level of the entry.
	Level() Level
	// Message returns the message of the entry.
	Message() string
	// Owner returns the log's owner.
	Owner() any
	// Request returns the request data.
	Request() map[string]any
	// Response returns the response data.
	Response() map[string]any
	// Tags returns the list of tags.
	Tags() []string
	// Time returns the timestamp of the entry.
	Time() time.Time
	// Trace returns the stack trace or trace data.
	Trace() map[string]any
	// User returns the user information.
	User() any
	// With returns additional context data.
	With() map[string]any
}

type Handler added in v1.17.0

type Handler interface {
	// Enabled reports whether the handler is enabled for the given level.
	Enabled(Level) bool
	// Handle handles the log entry.
	Handle(Entry) error
}

Handler is the interface for log handlers.

type Hook added in v1.0.0

type Hook interface {
	// Levels monitoring level
	Levels() []Level
	// Fire executes logic when trigger
	Fire(Entry) error
}

Hook is the interface for log hooks. Deprecated: Use Handler instead, Hook will be removed in v1.18.

type Level added in v1.0.0

type Level slog.Level

Level defines custom log levels for the logging system. We define custom levels that extend slog's built-in levels to support Panic and Fatal levels which are not part of the standard slog package.

func ParseLevel added in v1.0.1

func ParseLevel(lvl string) (Level, error)

ParseLevel takes a string level and returns the log level constant.

func (Level) Level added in v1.17.0

func (level Level) Level() slog.Level

Level implements the slog.Leveler interface.

func (Level) MarshalText added in v1.0.1

func (level Level) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Level) String added in v1.0.1

func (level Level) String() string

String converts the Level to a string. E.g. LevelPanic becomes "panic".

func (*Level) UnmarshalText added in v1.0.1

func (level *Level) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Log added in v1.0.0

type Log interface {
	// WithContext adds a context to the logger.
	WithContext(ctx context.Context) Log
	// Channel return a writer for a specific channel.
	Channel(channel string) Log
	// Stack return a writer for multiple channels.
	Stack(channels []string) Log
	// Writer returns the underlying Writer.
	Writer
}

type Logger

type Logger interface {
	// Handle returns a Handler for the given channel config path.
	Handle(channel string) (Handler, error)
}

Logger is the interface for custom log drivers.

type Writer added in v1.2.3

type Writer interface {
	// Debug logs a message at LevelDebug.
	Debug(args ...any)
	// Debugf is equivalent to Debug, but with support for fmt.Printf-style arguments.
	Debugf(format string, args ...any)
	// Info logs a message at LevelInfo.
	Info(args ...any)
	// Infof is equivalent to Info, but with support for fmt.Printf-style arguments.
	Infof(format string, args ...any)
	// Warning logs a message at LevelWarning.
	Warning(args ...any)
	// Warningf is equivalent to Warning, but with support for fmt.Printf-style arguments.
	Warningf(format string, args ...any)
	// Error logs a message at LevelError.
	Error(args ...any)
	// Errorf is equivalent to Error, but with support for fmt.Printf-style arguments.
	Errorf(format string, args ...any)
	// Fatal logs a message at LevelFatal.
	Fatal(args ...any)
	// Fatalf is equivalent to Fatal, but with support for fmt.Printf-style arguments.
	Fatalf(format string, args ...any)
	// Panic logs a message at LevelPanic.
	Panic(args ...any)
	// Panicf is equivalent to Panic, but with support for fmt.Printf-style arguments.
	Panicf(format string, args ...any)
	// Code set a code or slug that describes the error.
	// Error messages are intended to be read by humans, but such code is expected to
	// be read by machines and even transported over different services.
	Code(code string) Writer
	// Hint set a hint for faster debugging.
	Hint(hint string) Writer
	// In sets the feature category or domain in which the log entry is relevant.
	In(domain string) Writer
	// Owner set the name/email of the colleague/team responsible for handling this error.
	// Useful for alerting purpose.
	Owner(owner any) Writer
	// Request supplies a http.Request.
	Request(req http.ContextRequest) Writer
	// Response supplies a http.Response.
	Response(res http.ContextResponse) Writer
	// Tags add multiple tags, describing the feature returning an error.
	Tags(tags ...string) Writer
	// User sets the user associated with the log entry.
	User(user any) Writer
	// With adds key-value pairs to the context of the log entry
	With(data map[string]any) Writer
	// WithTrace adds a stack trace to the log entry.
	WithTrace() Writer
}

Jump to

Keyboard shortcuts

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