clilog

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 8 Imported by: 3

README

clilog

Go Reference

Package clilog provides a slog.Handler for command line tools.

Documentation

Overview

Package clilog provides a slog.Handler for command line tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CLIHandler

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

CLIHandler implements a slog.Handler for command line tools. The output format of CLIHandler is designed to be human readable.

func NewCLIHandler

func NewCLIHandler(w io.Writer, opts *HandlerOptions) *CLIHandler

NewCLIHandler returns a new CLIHandler.

func (*CLIHandler) Enabled

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

Enabled reports whether the handler handles records at the given level. The handler ignores records whose level is lower.

func (*CLIHandler) Handle

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

Handle handles the Record.

func (*CLIHandler) WithAttrs

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

WithAttrs returns a new Handler whose attributes consist of both the receiver's attributes and the arguments.

func (*CLIHandler) WithGroup

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

WithGroup returns a new Handler with the given group appended to the receiver's existing groups.

type HandlerOptions

type HandlerOptions struct {
	// AddSource causes the handler to output the source code
	// position of the log statement.
	AddSource bool

	// Level reports the minimum record level that will be logged.
	// The handler discards records with lower levels. If Level is
	// nil, the handler assumes LevelInfo. The handler calls
	// Level.Level for each record processed; to adjust the
	// minimum level dynamically, use a LevelVar.
	Level slog.Leveler
}

HandlerOptions are options for a CLIHandler. A zero HandlerOptions consists entirely of default values.

Jump to

Keyboard shortcuts

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