log

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2025 License: MIT Imports: 13 Imported by: 0

README

Log

License

Log is a simple go logging package that is a wrapper aroung slog.

Install

go get github.com/RevittCo/log

Handler Interface

You can create your own handler for use with this package. Just make it implement this interface.

type Handler interface {
    Enabled(ctx context.Context, l slog.Level) bool
    Handle(ctx context.Context, r slog.Record) error
    WithAttrs(attrs []slog.Attr) slog.Handler
    WithGroup(name string) slog.Handler
}

Usage

log.SetDefault(log.NewLogger(log.NewTerminalHandler(os.Stdout, log.LevelInfo)))
log.Info("logger initialised")

Documentation

Index

Constants

View Source
const (
	TerminalColourReset = "\033[0m"
	TerminalColourError = "\x1b[31m"
	TerminalColourWarn  = "\x1b[33m"
	TerminalColourInfo  = "\x1b[32m"
	TerminalColourDebug = "\x1b[36m"
	TerminalColourCrit  = "\x1b[35m"
	TerminalColourKey   = "\033[96m"
	TerminalTimeFormat  = "2006-01-02 15:04:05"
)
View Source
const (
	LevelDebug = Level(slog.LevelDebug)
	LevelInfo  = Level(slog.LevelInfo)
	LevelWarn  = Level(slog.LevelWarn)
	LevelError = Level(slog.LevelError)
	LevelCrit  = Level(slog.Level(12))
)

Variables

This section is empty.

Functions

func Crit

func Crit(msg string, ctx ...interface{})

func Debug

func Debug(msg string, ctx ...interface{})

func Error

func Error(msg string, ctx ...interface{})

func Info

func Info(msg string, ctx ...interface{})

func NewMultiHandler

func NewMultiHandler(handlers ...slog.Handler) slog.Handler

func SetDefault

func SetDefault(l Logger)

func Warn

func Warn(msg string, ctx ...interface{})

Types

type Level

type Level int

Level represents the logging level. -4: Debug 0: Info 4: Warn 8: Error 12: Critical

func LevelFromSlog

func LevelFromSlog(l slog.Level) Level

func (Level) Level

func (l Level) Level() slog.Level

func (Level) MarshalJSON

func (l Level) MarshalJSON() ([]byte, error)

func (Level) MarshalText

func (l Level) MarshalText() ([]byte, error)

func (Level) String

func (l Level) String() string

func (Level) TerminalString

func (l Level) TerminalString() string

func (*Level) UnmarshalJSON

func (l *Level) UnmarshalJSON(data []byte) error

func (*Level) UnmarshalText

func (l *Level) UnmarshalText(data []byte) error

type Logger

type Logger interface {
	Log(level Level, msg string, attrs ...any)
	Debug(msg string, ctx ...interface{})
	Info(msg string, ctx ...interface{})
	Warn(msg string, ctx ...interface{})
	Error(msg string, ctx ...interface{})
	Crit(msg string, ctx ...interface{})
	Handler() slog.Handler
	Enabled(ctx context.Context, level Level) bool
	With(ctx ...interface{}) Logger
	WithGroup(name string) Logger
	New(ctx ...interface{}) Logger
}

func New

func New(ctx ...interface{}) Logger

func NewLogger

func NewLogger(h slog.Handler) Logger

func Root

func Root() Logger

type MultiHandler

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

func (*MultiHandler) Enabled

func (h *MultiHandler) Enabled(ctx context.Context, l slog.Level) bool

func (*MultiHandler) Handle

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

func (*MultiHandler) WithAttrs

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

func (*MultiHandler) WithGroup

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

type TerminalHandler

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

func NewTerminalHandler

func NewTerminalHandler(writer io.Writer, level Level) *TerminalHandler

func (*TerminalHandler) Enabled

func (h *TerminalHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*TerminalHandler) Handle

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

func (*TerminalHandler) WithAttrs

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

func (*TerminalHandler) WithGroup

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

Jump to

Keyboard shortcuts

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