log

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package log provides utilities for structured logging in applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

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

Debug logs a debug message using the default logger.

func Error

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

Error logs an error message using the default logger.

func Info

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

Info logs an informational message using the default logger.

func Set

func Set(logger Logger)

Set sets the provided logger as the default logger.

func Warn

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

Warn logs a warning message using the default logger.

Types

type Color added in v0.2.1

type Color string

Color represents a terminal color escape code.

const (
	Black   Color = "\033[30m"       // Black color
	Red     Color = "\033[31m"       // Red color
	Green   Color = "\033[32m"       // Green color
	Yellow  Color = "\033[33m"       // Yellow color
	Blue    Color = "\033[34m"       // Blue color
	Magenta Color = "\033[35m"       // Magenta color
	Cyan    Color = "\033[36m"       // Cyan color
	White   Color = "\033[37m"       // White color
	Orange  Color = "\033[38;5;208m" // Orange color (using extended color)
)

Predefined terminal color escape codes.

type Logger

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

Logger is an interface that defines methods for structured logging.

func Default

func Default() Logger

Default returns the currently set default logger.

func New added in v0.3.3

func New(prefix string, color Color, colorless bool) Logger

Create a new logger with the specified prefix and color settings.

func NewColored added in v0.2.1

func NewColored(base Logger, color Color) Logger

NewColored wraps an existing Logger and applies ANSI color to its messages.

func NewMock

func NewMock() Logger

NewMock creates and returns a new instance of Mock logger.

func NewPrefixed

func NewPrefixed(prefix string, original Logger) Logger

NewPrefixed creates a new Logger that prefixes all log messages with the specified prefix.

func NewZerolog

func NewZerolog(writer io.Writer, level string, colorless bool) Logger

NewZerolog creates a new Logger with the specified log level and writer. Details: https://github.com/rs/zerolog

type Mock

type Mock struct {
	Messages []string
}

Mock is a Mock logger that collects log messages for testing purposes.

func (*Mock) Debug

func (m *Mock) Debug(msg string, args ...any)

Debug logs a debug message with optional arguments.

func (*Mock) Error

func (m *Mock) Error(msg string, args ...any)

Error logs an error message with optional arguments.

func (*Mock) Info

func (m *Mock) Info(msg string, args ...any)

Info logs an informational message with optional arguments.

func (*Mock) Warn

func (m *Mock) Warn(msg string, args ...any)

Warn logs a warning message with optional arguments.

Jump to

Keyboard shortcuts

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