log

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package log provides logging utilities.

This package implements structured logging with support for different output formats and log levels. Generally, it should only be used in the main package.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidArgument  = errors.New("invalid argument")
	ErrUnknownLogLevel  = errors.New("unknown log level")
	ErrUnknownLogFormat = errors.New("unknown log format")
)
View Source
var ErrBufferFull = errors.New("buffer is full")

ErrBufferFull indicates that the buffer has reached its maximum capacity.

Functions

func CreateHandler

func CreateHandler(w io.Writer, logLvl slog.Level, logFmt Format) slog.Handler

func CreateHandlerWithStrings

func CreateHandlerWithStrings(w io.Writer, logLevel, logFormat string) (slog.Handler, error)

CreateHandlerWithStrings creates a slog.Handler by strings.

func GetLevel

func GetLevel(level string) (slog.Level, error)

Types

type CircularBuffer

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

CircularBuffer is a thread-safe circular buffer that implements io.Writer. It stores a fixed number of recent entries, automatically overwriting the oldest entries when the buffer is full.

func NewCircularBuffer

func NewCircularBuffer(capacity int) *CircularBuffer

NewCircularBuffer creates a new circular buffer with the specified capacity. The capacity determines the maximum number of entries that can be stored.

func (*CircularBuffer) Capacity

func (cb *CircularBuffer) Capacity() int

Capacity returns the maximum number of entries the buffer can hold.

func (*CircularBuffer) Clear

func (cb *CircularBuffer) Clear()

Clear removes all entries from the buffer.

func (*CircularBuffer) Entries

func (cb *CircularBuffer) Entries() [][]byte

Entries returns a copy of all current entries in chronological order (oldest first). The returned slice is safe to modify.

func (*CircularBuffer) IsFull

func (cb *CircularBuffer) IsFull() bool

IsFull returns true if the buffer has reached its maximum capacity.

func (*CircularBuffer) Size

func (cb *CircularBuffer) Size() int

Size returns the current number of entries in the buffer.

func (*CircularBuffer) Write

func (cb *CircularBuffer) Write(p []byte) (int, error)

Write implements io.Writer. It stores the provided data as a new entry in the circular buffer. If the buffer is full, it overwrites the oldest entry. The data is copied to prevent external modifications.

func (*CircularBuffer) WriteTo

func (cb *CircularBuffer) WriteTo(w io.Writer) (int64, error)

WriteTo writes all current entries to the provided writer in chronological order. It implements io.WriterTo for efficient bulk transfers.

type Format

type Format string
const (
	FormatJSON   Format = "json"
	FormatLogfmt Format = "logfmt"
	FormatText   Format = "text"
)

func GetFormat

func GetFormat(format string) (Format, error)

Jump to

Keyboard shortcuts

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