sloghandler

package
v0.7.12 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package sloghandler provides a slog.Handler adapter for clog.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(logger *clog.Logger, opts *Options) slog.Handler

New creates a slog.Handler that routes slog.Record entries through the given clog clog.Logger.

Types

type Handler

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

Handler implements slog.Handler by routing records through a clog clog.Logger.

func (*Handler) Enabled

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

Enabled reports whether the handler handles records at the given level.

func (*Handler) Handle

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

Handle converts a slog.Record into a clog event and logs it.

func (*Handler) WithAttrs

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

WithAttrs returns a new Handler with the given attrs preset.

func (*Handler) WithGroup

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

WithGroup returns a new Handler with the given group name appended.

type Options

type Options struct {
	// AddSource adds source file:line information to each log entry.
	AddSource bool
	// Level overrides the minimum log level. If nil, the logger's level is used.
	Level slog.Leveler
}

Options configures a Handler.

Jump to

Keyboard shortcuts

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