log

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2025 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package log is a helper for the slog package for configuring and connecting to command line application.

Index

Constants

View Source
const (
	LevelTrace = slog.Level(-8)
	LevelDebug = slog.LevelDebug
	LevelInfo  = slog.LevelInfo
	LevelWarn  = slog.LevelWarn
	LevelError = slog.LevelError
)

Variables

This section is empty.

Functions

func Format

func Format(format, key string, value any) slog.Attr

func FromContext

func FromContext(ctx context.Context) *slog.Logger

FromContext retrieves the logger from context or fallbacks to slog.Default().

func New

func New(opts *Options) (*slog.Logger, error)

func WithFilter

func WithFilter(filter func(string) (string, []slog.Attr)) func(*Legacy)

func WithLevel

func WithLevel(level slog.Level) func(*Legacy)

func WithLogger

func WithLogger(ctx context.Context, logger *slog.Logger) context.Context

WithLogger injects the logger into context.

Types

type Legacy

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

Legacy is a structured logger that implements common logger interfaces.

func NewLegacy

func NewLegacy(logger *slog.Logger, opts ...func(*Legacy)) Legacy

NewLegacy creates a new Legacy logger that write to the provided slog.Logger.

func (Legacy) Printf

func (l Legacy) Printf(format string, v ...any)

Printf formats according to a format specifier and writes to the logger.

func (Legacy) Println

func (l Legacy) Println(v ...any)

Println formats using the default formats for its operands and writes to the logger.

type Options

type Options struct {
	Writer   io.Writer
	Filename string
	// contains filtered or unexported fields
}

Options holds the results of the command line flags.

func NewOptions

func NewOptions(f flagSet) *Options

NewOptions add flags to the command line. Works for cobra and the standard library.

Jump to

Keyboard shortcuts

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