logger

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Err

func Err(err error) slog.Attr

Err is a helper function to ensure errors are always logged with the key "err". Additionally this becomes the single point in code, where we could tweak how errors are logged, e.g. to handle application specific error types or to add stack trace information in debug mode.

func NewWebhookLogger added in v0.2.0

func NewWebhookLogger(cfg api.SystemSettingsLog) (slog.Handler, error)

func ParseLevel added in v0.2.0

func ParseLevel(levelStr string) slog.Level

func SlogBackedLogrus

func SlogBackedLogrus() *logrus.Logger

func ValidateLevel added in v0.2.0

func ValidateLevel(levelStr string) error

func WebhookConfigChanged added in v0.2.0

func WebhookConfigChanged(oldCfgs, newCfgs []api.SystemSettingsLog) bool

func WebhookDefaultConfig added in v0.2.0

func WebhookDefaultConfig(cfg api.SystemSettingsLog) api.SystemSettingsLog

func WebhookValidateConfig added in v0.2.0

func WebhookValidateConfig(cfg api.SystemSettingsLog) error

Types

type Handler added in v0.2.0

type Handler struct {
	*slog.LevelVar
	// contains filtered or unexported fields
}

func InitLogger

func InitLogger(filepath string, verbose bool, debug bool) (*Handler, error)

func NewLogHandler added in v0.2.0

func NewLogHandler(level slog.Level, options slog.HandlerOptions) *Handler

NewLogHandler creates a new log handler with the given default options, level, and sub-handlers.

func (*Handler) AddHandler added in v0.2.0

func (h *Handler) AddHandler(handler slog.Handler)

func (*Handler) Enabled added in v0.2.0

func (h *Handler) Enabled(ctx context.Context, lvl slog.Level) bool

Enabled returns true if any logger is enabled for the level.

func (*Handler) Handle added in v0.2.0

func (h *Handler) Handle(ctx context.Context, rec slog.Record) error

Handle calls Handle for all handlers for which log level is enabled. Errors will be collected and returned together.

func (*Handler) SendLifecycle added in v0.2.0

func (h *Handler) SendLifecycle(ctx context.Context, event api.EventLifecycle)

func (*Handler) SetHandlers added in v0.2.0

func (h *Handler) SetHandlers(cfgs []api.SystemSettingsLog) error

SetHandlers replaces the log handler set with additional config-based handlers, keeping any default handlers.

func (*Handler) WithAttrs added in v0.2.0

func (h *Handler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new MultiLog with WithAttrs called on all handlers.

func (*Handler) WithGroup added in v0.2.0

func (h *Handler) WithGroup(name string) slog.Handler

WithGroup returns a new MultiLog with WithGroup called on all handlers.

type Logger

type Logger interface {
	Debug(msg string, args ...any)
	DebugContext(ctx context.Context, msg string, args ...any)
	Error(msg string, args ...any)
	ErrorContext(ctx context.Context, msg string, args ...any)
	Info(msg string, args ...any)
	InfoContext(ctx context.Context, msg string, args ...any)
	Warn(msg string, args ...any)
	WarnContext(ctx context.Context, msg string, args ...any)
	With(args ...any) *slog.Logger
}

Jump to

Keyboard shortcuts

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