Skip to content

Latest commit

 

History

History
341 lines (221 loc) · 6.41 KB

README.md

File metadata and controls

341 lines (221 loc) · 6.41 KB

clog

import "github.com/periaate/blume/clog"

Package clog wraps log/slog with a normalized indent, humanized, and colorized style.

Example:

DEBUG @ main.go:111      MSG:<a message>; KEY:<Values here>; err:<nil>;
DEBUG @ main.go:111      MSG:<another message>; KEY:<Values here longer value>; err:<nil>;
DEBUG @ main.go:111      MSG:<a message>;       KEY:<err will be adjusted>;     err:<nil>;

## TODO

  • Rewrite the handler for greater flexibility and customization.
  • Decide whether to use external libraries for coloring and formatting.

Index

Constants

const (
    LevelError = slog.LevelError
    LevelInfo  = slog.LevelInfo
    LevelWarn  = slog.LevelWarn
    LevelDebug = slog.LevelDebug
)

func Debug

func Debug(msg string, args ...any)

Debug logs with the default clog logger.

func DefaultClog

func DefaultClog() *slog.Logger

func Error

func Error(msg string, args ...any)

Error logs with the default clog logger.

func Fatal

func Fatal(msg string, args ...any)

Error logs with the "ERROR" level and exits the program with code 1.

func GetDefaultClog

func GetDefaultClog() *slog.Logger

func Info

func Info(msg string, args ...any)

Info logs with the default clog logger.

func MaxLen

func MaxLen(l int) func(*ClogHandler)

func NewClog

func NewClog(w io.Writer, lvl slog.Level, opts ...func(*ClogHandler)) *slog.Logger

NewClog creates a new clog logger with the given writer, level, and options.

func SetDefaultClog

func SetDefaultClog(l *slog.Logger)

func SetLogLoggerLevel

func SetLogLoggerLevel(lvl slog.Level)

func Style

func Style(st *Styles) func(*ClogHandler)

func Warn

func Warn(msg string, args ...any)

Warn logs with the default clog logger.

type ClogHandler

ClogHandler is a log/slog handler.

type ClogHandler struct {
    St    *Styles
    Level slog.Leveler
    Lvl   int

    Mut *sync.Mutex
    Out io.Writer

    // MaxLen is the maximum length of a single value. If the value is longer, it will be cut.
    MaxLen int
    // contains filtered or unexported fields
}

func New

func New(out io.Writer, lvl slog.Level, st *Styles) *ClogHandler

func (*ClogHandler) DefGetV

func (h *ClogHandler) DefGetV(vall slog.Value) string

func (*ClogHandler) Enabled

func (h *ClogHandler) Enabled(ctx context.Context, lvl slog.Level) bool

func (*ClogHandler) Handle

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

func (*ClogHandler) SetLogLoggerLevel

func (l *ClogHandler) SetLogLoggerLevel(lvl slog.Level)

func (*ClogHandler) WithAttrs

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

func (*ClogHandler) WithGroup

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

type Dummy

Dummy is a dummy logger that does nothing.

type Dummy struct{}

func (Dummy) Debug

func (Dummy) Debug(_ string, _ ...any)

func (Dummy) Error

func (Dummy) Error(_ string, _ ...any)

func (Dummy) Info

func (Dummy) Info(_ string, _ ...any)

func (Dummy) Warn

func (Dummy) Warn(_ string, _ ...any)

type Logger

type Logger interface {
    Error(msg string, args ...any)
    Info(msg string, args ...any)
    Warn(msg string, args ...any)
    Debug(msg string, args ...any)
}

type Styles

type Styles struct {
    TimeStamp bool
    Delim     [2]string
}

func NewStyles

func NewStyles(st *Styles) *Styles

Generated by gomarkdoc