Documentation
¶
Index ¶
- Constants
- func NewCLIHandler(w io.Writer, opts ...CLIHandlerOption) slog.Handler
- type AffixStyle
- type AttrStyle
- type CLIHandler
- type CLIHandlerOption
- func WithAttrHandler(fn func(a slog.Attr) slog.Attr) CLIHandlerOption
- func WithCaller(has bool) CLIHandlerOption
- func WithLabel(prefix string) CLIHandlerOption
- func WithLevel(level slog.Leveler) CLIHandlerOption
- func WithStyle(s *Style) CLIHandlerOption
- func WithTime(has bool) CLIHandlerOption
- func WithTimeFormat(layout string) CLIHandlerOption
- type CallerStyle
- type Color
- type LabelStyle
- type LevelStyle
- type Logger
- type Style
- type StyleOption
Constants ¶
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 ¶
AffixStyle config for text affixes.
type CLIHandler ¶
type CLIHandler struct {
// contains filtered or unexported fields
}
CLIHandler is a slog.Handler for colored CLI output.
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 (*Color) WriteBytes ¶
WriteBytes writes the bytes 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 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 Style3 ¶
func Style3() *Style
Style3 returns a logging style with labeled levels and basic background colors.
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.