logger

package
v0.0.0-...-5a5a655 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Reset   = "\033[0m"
	Red     = "\033[31m"
	Green   = "\033[32m"
	Yellow  = "\033[33m"
	Blue    = "\033[34m"
	Magenta = "\033[35m"
	Cyan    = "\033[36m"
	White   = "\033[37m"
)

ANSI color codes for terminal output

View Source
const LevelFatal slog.Level = slog.Level(12)

LevelFatal defines a new slog level for fatal errors

Variables

View Source
var (
	ExitFunc = os.Exit // ExitFunc represents the exit function (used for testing)

)

Global variables

Functions

func Debug

func Debug(first any, args ...any)

Logging functions

func Error

func Error(first any, args ...any)

func Fatal

func Fatal(first any, args ...any)

func Info

func Info(first any, args ...any)

func Initialize

func Initialize(logLevel string) *slog.Logger

Initialize sets up the logger with the specified log level

func SetExitHandler

func SetExitHandler(handler ExitHandler)

SetExitHandler sets the handler for fatal exits

func Warn

func Warn(first any, args ...any)

Types

type ComponentType

type ComponentType string

ComponentType represents the type of component for logging identification

const (
	APP   ComponentType = "[APP]"
	BLE   ComponentType = "[BLE]"
	SPEED ComponentType = "[SPD]"
	VIDEO ComponentType = "[VID]"
)

Supported component types

type CustomTextHandler

type CustomTextHandler struct {
	slog.Handler
	// contains filtered or unexported fields
}

CustomTextHandler represents a custom text handler for log formatting

func NewCustomTextHandler

func NewCustomTextHandler(w io.Writer, opts *slog.HandlerOptions) *CustomTextHandler

NewCustomTextHandler creates a new custom text handler with the specified options

func (*CustomTextHandler) Enabled

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

Enabled returns true if the specified log level is enabled

func (*CustomTextHandler) Handle

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

Handle handles the log record and writes it to the output stream

func (*CustomTextHandler) WithAttrs

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

WithAttrs returns a new handler with the specified attributes

func (*CustomTextHandler) WithGroup

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

WithGroup returns a new handler with the specified group name

type ExitHandler

type ExitHandler func()

ExitHandler is a function type for handling fatal exits

Jump to

Keyboard shortcuts

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