slogger

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 20 Imported by: 0

README

slogger

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Module

func Module(parts ...string) slog.Attr

func TestLogger

func TestLogger() *slog.Logger

Types

type Bundle

type Bundle struct {
	Logger  *slog.Logger
	Closers []func() error
}

func New

func New(cfg Config) (*Bundle, error)

func (*Bundle) Close

func (b *Bundle) Close() error

type Config

type Config struct {
	Fields map[string]any `json:"fields" yaml:"fields" toml:"fields"`
	Sinks  []SinkConfig   `json:"sinks" yaml:"sinks" toml:"sinks"`
}

type FormatType

type FormatType string
const (
	FormatText   FormatType = "text"
	FormatPretty FormatType = "pretty"
	FormatJSON   FormatType = "json"
)

type PrettyTextHandler

type PrettyTextHandler struct {
	// contains filtered or unexported fields
}

func NewPrettyTextHandler

func NewPrettyTextHandler(w io.Writer, opts *slog.HandlerOptions) *PrettyTextHandler

func NewPrettyTextHandlerWithOptions

func NewPrettyTextHandlerWithOptions(w io.Writer, opts *PrettyTextHandlerOptions) *PrettyTextHandler

func (*PrettyTextHandler) Enabled

func (h *PrettyTextHandler) Enabled(_ context.Context, level slog.Level) bool

func (*PrettyTextHandler) Handle

func (*PrettyTextHandler) WithAttrs

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

func (*PrettyTextHandler) WithGroup

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

type PrettyTextHandlerOptions

type PrettyTextHandlerOptions struct {
	HandlerOptions *slog.HandlerOptions
	SourceCut      string
}

type RotationConfig

type RotationConfig struct {
	Enabled    bool `toml:"enabled" json:"enabled"`
	MaxSizeMB  int  `toml:"max_size_mb" json:"max_size_mb"`
	MaxBackups int  `toml:"max_backups" json:"max_backups"`
	MaxAgeDays int  `toml:"max_age_days" json:"max_age_days"`
	Compress   bool `toml:"compress" json:"compress"`
	LocalTime  bool `toml:"local_time" json:"local_time"`
}

type SinkConfig

type SinkConfig struct {
	Type      SinkType        `json:"type" yaml:"type" toml:"type"`
	Format    FormatType      `json:"format" yaml:"format" toml:"format"`
	Level     string          `json:"level" yaml:"level" toml:"level"`
	AddSource bool            `json:"add_source" yaml:"add_source" toml:"add_source"`
	Filepath  string          `json:"filepath" yaml:"filepath" toml:"filepath"`
	Rotation  *RotationConfig `json:"rotation" yaml:"rotation" toml:"rotation"`
}

type SinkType

type SinkType string
const (
	SinkStdout SinkType = "stdout"
	SinkFile   SinkType = "file"
)

Jump to

Keyboard shortcuts

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