log

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2025 License: GPL-2.0 Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ArgLevel  = "logger.level"
	ArgFormat = "logger.format"
)
View Source
const (
	RequestIDContextKey contextKey = 0
)

Variables

View Source
var Noop slog.Handler = noopHandler{}

Noop is a Handler which is always disabled and therefore logs nothing.

Functions

func NewLogger

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

func NoopLogger

func NoopLogger() *slog.Logger

NoopLogger returns a new slog.Logger that logs nothing.

Types

type Format

type Format int

Format determines what kind of output is written by the logger.

const (
	FormatText Format = iota
	FormatJSON
)

Common log types.

func (Format) String

func (i Format) String() string

func (*Format) UnmarshalText

func (lt *Format) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Handler

type Handler struct {
	slog.Handler
}

Handler is a struct that embeds slog.Handler to provide additional functionality or customization for handling logs in the application. This Handler enables request ID functionality by adding a request_id to the log records if available in the context.

func NewLogHandler

func NewLogHandler(h slog.Handler) *Handler

func (*Handler) Handle

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

func (*Handler) WithAttrs

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

Jump to

Keyboard shortcuts

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