logging

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package logging provides structured logging for Sentinel.

Index

Constants

View Source
const (
	LevelDebug = slog.LevelDebug
	LevelInfo  = slog.LevelInfo
	LevelWarn  = slog.LevelWarn
	LevelError = slog.LevelError
)

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, args ...any)

func Error

func Error(msg string, args ...any)

func Info

func Info(msg string, args ...any)

func SetDefault

func SetDefault(l *Logger)

SetDefault sets the default logger.

func Warn

func Warn(msg string, args ...any)

func WithContext

func WithContext(ctx context.Context, l *Logger) context.Context

WithContext adds the logger to context.

Types

type Config

type Config struct {
	Level  Level
	Format string // "json" or "text"
	Output io.Writer
}

Config configures the logger.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default logger configuration.

type Level

type Level = slog.Level

Level represents log levels.

type Logger

type Logger struct {
	*slog.Logger
}

Logger wraps slog.Logger with convenience methods.

func Default

func Default() *Logger

Default returns the default logger.

func FromContext

func FromContext(ctx context.Context) *Logger

FromContext retrieves the logger from context.

func New

func New(cfg *Config) *Logger

New creates a new structured logger.

func (*Logger) WithComponent

func (l *Logger) WithComponent(name string) *Logger

WithComponent returns a logger with a component field.

func (*Logger) WithError

func (l *Logger) WithError(err error) *Logger

WithError returns a logger with an error field.

func (*Logger) WithFields

func (l *Logger) WithFields(fields map[string]any) *Logger

WithFields returns a logger with additional fields.

func (*Logger) WithNode

func (l *Logger) WithNode(name string) *Logger

WithNode returns a logger with a node field.

Jump to

Keyboard shortcuts

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