logger

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package logger configures native slog with recursive structured-field redaction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Context

func Context(ctx context.Context, attrs ...slog.Attr) context.Context

Context adds correlation attributes without retaining the context in a client.

func SetDefault added in v1.1.0

func SetDefault(l *Logger)

SetDefault installs l as the process default logger.

Types

type Config

type Config struct {
	JSON                                      bool
	Level                                     slog.Level
	Output                                    io.Writer
	OwnOutput                                 bool
	File                                      string
	MaxSizeMB, MaxBackups, MaxAgeDays         int
	Compress                                  bool
	Service, Version, Environment, TimeFormat string
	SanitizeText                              func(string) string
}

Config contains explicit constructor settings; see package documentation for defaults.

type Level added in v1.1.0

type Level = slog.Level

Level is the standard logging threshold exposed without requiring consumers to import slog directly.

func ParseLevel added in v1.1.0

func ParseLevel(value string) Level

ParseLevel parses a textual level and falls back to Info when invalid.

type Logger

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

Logger embeds native slog and owns applicable configured outputs.

func Default added in v1.1.0

func Default() *Logger

Default returns a wrapper around the process default logger.

func From

func From(l *slog.Logger) *Logger

From wraps an existing logger. Its handler and lifecycle remain caller-owned.

func New

func New(c Config) *Logger

New constructs and validates an explicitly owned instance. See package documentation for defaults and cleanup.

func Open

func Open(c Config) (*Logger, error)

Open validates output settings and eagerly checks file access. New remains available for callers that deliberately use slog's lazy write error handling.

func (*Logger) Close

func (l *Logger) Close() error

Close releases owned resources. See package documentation for shutdown ordering.

func (*Logger) Flush

func (l *Logger) Flush(ctx context.Context) error

Flush invokes a configured writer's flush contract. Injected writers remain caller-owned unless OwnOutput is explicitly enabled. Call after producers stop.

func (*Logger) SetLevel

func (l *Logger) SetLevel(v slog.Level)

SetLevel changes the shared dynamic logging threshold.

func (*Logger) With

func (l *Logger) With(args ...any) *Logger

With returns a logger enriched with structured attributes.

func (*Logger) WithContext

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

WithContext copies logger correlation attributes from the supplied context.

func (*Logger) WithError

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

WithError returns a logger with an error attribute; error text must be safe for logging.

Jump to

Keyboard shortcuts

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