logger

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package logger provides a slog.Logger that can be configured via environment variables. CONTRAST_LOG_LEVEL can be used to set the log level. CONTRAST_LOG_FORMAT can be used to set the log format. It also offer a slog.Handler that can be used to enable logging on a per-subsystem basis. CONTRAST_LOG_SUBSYSTEMS can be used to enable logging for specific subsystems. If CONTRAST_LOG_SUBSYSTEMS has the special value "*", all subsystems are enabled. Otherwise, a comma-separated list of subsystem names can be specified.

Index

Constants

View Source
const (
	// LogLevel is the environment variable used to set the log level.
	LogLevel = "CONTRAST_LOG_LEVEL"
	// LogFormat is the environment variable used to set the log format.
	LogFormat = "CONTRAST_LOG_FORMAT"
	// LogSubsystems is the environment variable used to enable logging for specific subsystems.
	LogSubsystems = "CONTRAST_LOG_SUBSYSTEMS"
)

Variables

This section is empty.

Functions

func Default

func Default() (*slog.Logger, error)

Default returns a logger configured via environment variables.

func NewNamed

func NewNamed(logger *slog.Logger, name string) *slog.Logger

NewNamed returns a new logger with the given name, using the handler from the previous logger.

Types

type Handler

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

Handler is a slog.Handler that can be used to enable logging on a per-subsystem basis.

func NewHandler

func NewHandler(inner slog.Handler, subsystem string) *Handler

NewHandler returns a new Handler.

func (*Handler) Enabled

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

Enabled returns true if the given level is enabled.

func (*Handler) Handle

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

Handle handles the given record.

func (*Handler) WithAttrs

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

WithAttrs returns a new Handler with the given attributes.

func (*Handler) WithGroup

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

WithGroup returns a new Handler with the given group.

Jump to

Keyboard shortcuts

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