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.
- Constants
- func Debug(msg string, args ...any)
- func DefaultClog() *slog.Logger
- func Error(msg string, args ...any)
- func Fatal(msg string, args ...any)
- func GetDefaultClog() *slog.Logger
- func Info(msg string, args ...any)
- func MaxLen(l int) func(*ClogHandler)
- func NewClog(w io.Writer, lvl slog.Level, opts ...func(*ClogHandler)) *slog.Logger
- func SetDefaultClog(l *slog.Logger)
- func SetLogLoggerLevel(lvl slog.Level)
- func Style(st *Styles) func(*ClogHandler)
- func Warn(msg string, args ...any)
- type ClogHandler
- func New(out io.Writer, lvl slog.Level, st *Styles) *ClogHandler
- func (h *ClogHandler) DefGetV(vall slog.Value) string
- func (h *ClogHandler) Enabled(ctx context.Context, lvl slog.Level) bool
- func (h *ClogHandler) Handle(ctx context.Context, r slog.Record) error
- func (l *ClogHandler) SetLogLoggerLevel(lvl slog.Level)
- func (h *ClogHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *ClogHandler) WithGroup(name string) slog.Handler
- type Dummy
- type Logger
- type Styles
const (
LevelError = slog.LevelError
LevelInfo = slog.LevelInfo
LevelWarn = slog.LevelWarn
LevelDebug = slog.LevelDebug
)
func Debug(msg string, args ...any)
Debug logs with the default clog logger.
func DefaultClog() *slog.Logger
func Error(msg string, args ...any)
Error logs with the default clog logger.
func Fatal(msg string, args ...any)
Error logs with the "ERROR" level and exits the program with code 1.
func GetDefaultClog() *slog.Logger
func Info(msg string, args ...any)
Info logs with the default clog logger.
func MaxLen(l int) func(*ClogHandler)
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(l *slog.Logger)
func SetLogLoggerLevel(lvl slog.Level)
func Style(st *Styles) func(*ClogHandler)
func Warn(msg string, args ...any)
Warn logs with the default clog logger.
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(out io.Writer, lvl slog.Level, st *Styles) *ClogHandler
func (h *ClogHandler) DefGetV(vall slog.Value) string
func (h *ClogHandler) Enabled(ctx context.Context, lvl slog.Level) bool
func (h *ClogHandler) Handle(ctx context.Context, r slog.Record) error
func (l *ClogHandler) SetLogLoggerLevel(lvl slog.Level)
func (h *ClogHandler) WithAttrs(attrs []slog.Attr) slog.Handler
func (h *ClogHandler) WithGroup(name string) slog.Handler
Dummy is a dummy logger that does nothing.
type Dummy struct{}
func (Dummy) Debug(_ string, _ ...any)
func (Dummy) Error(_ string, _ ...any)
func (Dummy) Info(_ string, _ ...any)
func (Dummy) Warn(_ string, _ ...any)
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 struct {
TimeStamp bool
Delim [2]string
}
func NewStyles(st *Styles) *Styles
Generated by gomarkdoc