utility

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogger

func NewLogger(level slog.Level) *slog.Logger

NewLogger creates a new instance of slog.Logger. The logging level can be specified by level. The returned logger writes info messages to STDOUT and warning, error, and debug messages to STDERR. The messages are color-coded for readability: debug messages are light gray, warning messages are yellow, and error messages are red.

Types

type ColorWriter

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

ColorWriter is a custom writer that adds color to the output.

func (*ColorWriter) Write

func (cw *ColorWriter) Write(p []byte) (n int, err error)

type LogHandler

type LogHandler struct {
	slog.Handler
	Debug *log.Logger
	Info  *log.Logger
	Warn  *log.Logger
	Error *log.Logger
}

LogHandler is a custom slog handler that routes log messages to different loggers based on their severity level. It embeds slog.Handler and defines loggers for different severity levels like Debug, Info, Warn, and Error.

func (*LogHandler) Handle

func (log *LogHandler) Handle(_ context.Context, r slog.Record) error

Jump to

Keyboard shortcuts

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