clog

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: BSD-3-Clause Imports: 13 Imported by: 1

README

GitHub Actions Go Version Go Report Card Codecov Go Reference

Clog

Color logging with golang.org/x/exp/slog. Clog mimics the zerolog.ConsoleWriter style but due to the slog.Handler implementation field order is preserved, whereas the zerolog.ConsoleWriter parses the json logs and sorts the fields.

Logging Sample

Stability

Clog will track the slog package including any breaking changes.

Documentation

Overview

Package clog provides a slog Handler that mimics the output of the zerolog.Logger.

Index

Constants

This section is empty.

Variables

View Source
var ErrorFieldName = "error"

ErrorFieldName is the field name used for error fields (zerolog does this).

Functions

func NewHandler

func NewHandler(w io.Writer) slog.Handler

NewHandler returns a Handler with the default options that writes to w.

func WithColor

func WithColor(c ColorOptions) func(*Handler)

WithColor is an option setting function for NewHandler. It sets the ColorOptions for the Handler.

func WithFormat

func WithFormat(f FormatOptions) func(*Handler)

WithFormat is an option setting function for NewHandler. It sets the FormatOptions for the Handler.

Types

type ColorOptions

type ColorOptions struct {
	Colorer ansi.Colorer
	Time    ansi.Color
	Field   ansi.Color
	Source  ansi.Color
	Level   map[slog.Level]ansi.Color
}

ColorOptions is a set of options for colorizing the output of a Handler.

type FormatOptions

type FormatOptions struct {
	Time  string
	Level map[slog.Level]string
}

FormatOptions is a set of options for formatting log messages.

type Handler

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

Handler implements an slog.Handler.

func (*Handler) Enabled

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

Enabled implements the slog.Handler interface.

func (*Handler) Handle

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

Handle implements the slog.Handler interface.

func (*Handler) WithAttrs

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

WithAttrs implements the slog.Handler interface.

func (*Handler) WithGroup

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

WithGroup implements the slog.Handler interface.

type HandlerOptions

type HandlerOptions slog.HandlerOptions

HandlerOptions is a set of options for a Handler.

func (HandlerOptions) NewHandler

func (o HandlerOptions) NewHandler(w io.Writer, opts ...func(*Handler)) slog.Handler

NewHandler returns a Handler the writes to w and invokes any option setting functions.

Directories

Path Synopsis
Package ansi provides ANSI escape codes for setting the foreground color of text.
Package ansi provides ANSI escape codes for setting the foreground color of text.
Package main provides a sample program for the clog package.
Package main provides a sample program for the clog package.

Jump to

Keyboard shortcuts

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