log

package
v0.0.0-...-22f70c5 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: GPL-2.0 Imports: 8 Imported by: 0

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