log

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Reset        = 0
	Bold         = 1
	Faint        = 2
	Italic       = 3
	Underline    = 4
	BlinkSlow    = 5
	BlinkRapid   = 6
	ReverseVideo = 7
	Concealed    = 8
	CrossedOut   = 9

	FgBlack   = 30
	FgRed     = 31
	FgGreen   = 32
	FgYellow  = 33
	FgBlue    = 34
	FgMagenta = 35
	FgCyan    = 36
	FgWhite   = 37

	FgHiBlack   = 90
	FgHiRed     = 91
	FgHiGreen   = 92
	FgHiYellow  = 93
	FgHiBlue    = 94
	FgHiMagenta = 95
	FgHiCyan    = 96
	FgHiWhite   = 97

	BgBlack   = 40
	BgRed     = 41
	BgGreen   = 42
	BgYellow  = 43
	BgBlue    = 44
	BgMagenta = 45
	BgCyan    = 46
	BgWhite   = 47

	BgHiBlack   = 100
	BgHiRed     = 101
	BgHiGreen   = 102
	BgHiYellow  = 103
	BgHiBlue    = 104
	BgHiMagenta = 105
	BgHiCyan    = 106
	BgHiWhite   = 107
)

SGR attributes used by Style.

Variables

This section is empty.

Functions

func NewCLIHandler

func NewCLIHandler(w io.Writer, opts ...CLIHandlerOption) slog.Handler

NewCLIHandler creates a new CLIHandler with the given options.

Types

type AffixStyle

type AffixStyle struct {
	Text  string
	Color *Color
}

AffixStyle config for text affixes.

type AttrStyle

type AttrStyle struct {
	KeyColor   *Color
	ValueColor *Color
	Separator  string
}

AttrStyle config for attributes.

type CLIHandler

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

CLIHandler is a slog.Handler for colored CLI output.

func (*CLIHandler) Enabled

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

Enabled reports whether the handler is enabled for the given level.

func (*CLIHandler) Handle

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

Handle handles a log record.

func (*CLIHandler) WithAttrs

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

WithAttrs returns a new handler with the given attributes.

func (*CLIHandler) WithGroup

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

WithGroup returns a new handler with the given group.

type CLIHandlerOption

type CLIHandlerOption func(*CLIHandler)

CLIHandlerOption defines a function type for configuring a CLIHandler.

func WithAttrHandler

func WithAttrHandler(fn func(a slog.Attr) slog.Attr) CLIHandlerOption

WithAttrHandler returns a CLIHandlerOption that sets the attribute handler function.

func WithCaller

func WithCaller(has bool) CLIHandlerOption

WithCaller returns a CLIHandlerOption that enables caller information.

func WithLabel added in v0.0.5

func WithLabel(prefix string) CLIHandlerOption

WithLabel returns a CLIHandlerOption that sets the prefix.

func WithLevel

func WithLevel(level slog.Leveler) CLIHandlerOption

WithLevel returns a CLIHandlerOption that sets the logging level.

func WithStyle

func WithStyle(s *Style) CLIHandlerOption

WithStyle returns a CLIHandlerOption that sets the logging style.

func WithTime

func WithTime(has bool) CLIHandlerOption

WithTime returns a CLIHandlerOption that enables time information.

func WithTimeFormat

func WithTimeFormat(layout string) CLIHandlerOption

WithTimeFormat returns a CLIHandlerOption that sets the time format.

type CallerStyle

type CallerStyle struct {
	Prefix AffixStyle
	Suffix AffixStyle
	Color  *Color
	Path   bool
}

CallerStyle config for caller source.

type Color

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

Color holds SGR sequences for text styling.

func NewColor

func NewColor(codes ...int) *Color

NewColor returns a new Color with the given SGR codes.

func (*Color) WriteBytes

func (c *Color) WriteBytes(buf *bytes.Buffer, b []byte)

WriteBytes writes the bytes to the buffer with SGR sequences applied.

func (*Color) WriteString

func (c *Color) WriteString(buf *bytes.Buffer, s string)

WriteString writes the string to the buffer with SGR sequences applied.

type LabelStyle

type LabelStyle struct {
	Prefix AffixStyle
	Suffix AffixStyle
	Color  *Color
	Width  int
}

LabelStyle config for the prefix.

type LevelStyle

type LevelStyle struct {
	Prefix AffixStyle
	Suffix AffixStyle
	Text   string
	Color  *Color
	Width  int
}

LevelStyle config for a log level.

type Logger

type Logger struct {
	*slog.Logger
}

Logger is a logger for the application.

func NewLogger

func NewLogger(handler slog.Handler) *Logger

NewLogger creates a new logger for the application.

type Style

type Style struct {
	Level  map[slog.Level]LevelStyle
	Label  LabelStyle
	Attr   AttrStyle
	Caller CallerStyle
}

Style holds style configuration for logging output.

func NewStyle

func NewStyle(opts ...StyleOption) *Style

NewStyle creates a new Style with the given options.

func Style0

func Style0() *Style

Style0 returns a basic logging style without colors.

func Style1

func Style1() *Style

Style1 returns a logging style with basic foreground colors.

func Style2

func Style2() *Style

Style2 returns a logging style with vivid foreground colors.

func Style3

func Style3() *Style

Style3 returns a logging style with labeled levels and basic background colors.

func Style4

func Style4() *Style

Style4 returns a logging style with labeled levels and vivid background colors.

func (*Style) Clone

func (s *Style) Clone() *Style

Clone returns a deep copy of the Style.

type StyleOption

type StyleOption func(*Style)

StyleOption defines a function type for configuring a Style.

func WithAttrStyle

func WithAttrStyle(attr AttrStyle) StyleOption

WithAttrStyle returns a StyleOption that sets the attribute style.

func WithCallerStyle

func WithCallerStyle(caller CallerStyle) StyleOption

WithCallerStyle returns a StyleOption that sets the caller style.

func WithLabelStyle

func WithLabelStyle(label LabelStyle) StyleOption

WithLabelStyle returns a StyleOption that sets the label style.

func WithLevelStyle

func WithLevelStyle(levels map[slog.Level]LevelStyle) StyleOption

WithLevelStyle returns a StyleOption that sets the logging level.

Jump to

Keyboard shortcuts

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