log

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StackDriver  = "stack"
	SingleDriver = "single"
	DailyDriver  = "daily"
	CustomDriver = "custom"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data map[string]any

type Entry

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
	// 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 Hook

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

type Level

type Level int
const (
	PanicLevel Level = iota
	FatalLevel
	ErrorLevel
	WarningLevel
	InfoLevel
	DebugLevel
)

func ParseLevel

func ParseLevel(lvl string) (Level, error)

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

func (Level) MarshalText

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

MarshalText implements encoding.TextMarshaler. It converts the Level to its text representation.

func (Level) String

func (level Level) String() string

Convert the Level to a string. E.g. PanicLevel becomes "panic".

func (*Level) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

type Log

type Log interface {
	// Debugf logs a message at DebugLevel.
	Debugf(format string, args ...any)
	// Infof logs a message at InfoLevel.
	Infof(format string, args ...any)
	// Warningf logs a message at WarningLevel.
	Warningf(format string, args ...any)
	// Warning logs a message at WarningLevel.
	Warning(args ...any)
	// Errorf logs a message at ErrorLevel.
	Errorf(format string, args ...any)
}

type Logger

type Logger interface {
	// Handle pass a channel config path here
	Handle(channel string) (Hook, error)
}

type NoopLogger

type NoopLogger struct{}

NoopLogger is a no-op logger that discards all messages.

func NewNoopLogger

func NewNoopLogger() *NoopLogger

NewNoopLogger creates a new no-op logger.

func (*NoopLogger) Debugf

func (l *NoopLogger) Debugf(format string, args ...any)

Debugf does nothing.

func (*NoopLogger) Errorf

func (l *NoopLogger) Errorf(format string, args ...any)

Errorf does nothing.

func (*NoopLogger) Infof

func (l *NoopLogger) Infof(format string, args ...any)

Infof does nothing.

func (*NoopLogger) Warning

func (l *NoopLogger) Warning(args ...any)

Warning does nothing.

func (*NoopLogger) Warningf

func (l *NoopLogger) Warningf(format string, args ...any)

Warningf does nothing.

type StdLogger

type StdLogger struct{}

StdLogger is a standard library logger implementation.

func NewStdLogger

func NewStdLogger() *StdLogger

NewStdLogger creates a new standard library logger.

func (*StdLogger) Debugf

func (l *StdLogger) Debugf(format string, args ...any)

Debugf logs a debug message.

func (*StdLogger) Errorf

func (l *StdLogger) Errorf(format string, args ...any)

Errorf logs an error message.

func (*StdLogger) Infof

func (l *StdLogger) Infof(format string, args ...any)

Infof logs an info message.

func (*StdLogger) Warning

func (l *StdLogger) Warning(args ...any)

Warning logs a warning message.

func (*StdLogger) Warningf

func (l *StdLogger) Warningf(format string, args ...any)

Warningf logs a warning message.

type Writer

type Writer interface {
	// Debug logs a message at DebugLevel.
	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 InfoLevel.
	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 WarningLevel.
	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 ErrorLevel.
	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 FatalLevel.
	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 PanicLevel.
	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
	// 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