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
- Variables
- func CreateHandler(w io.Writer, logLvl slog.Level, logFmt Format) slog.Handler
- func CreateHandlerWithStrings(w io.Writer, logLevel, logFormat string) (slog.Handler, error)
- func GetLevel(level string) (slog.Level, error)
- type CircularBuffer
- func (cb *CircularBuffer) Capacity() int
- func (cb *CircularBuffer) Clear()
- func (cb *CircularBuffer) Entries() [][]byte
- func (cb *CircularBuffer) IsFull() bool
- func (cb *CircularBuffer) Size() int
- func (cb *CircularBuffer) Write(p []byte) (int, error)
- func (cb *CircularBuffer) WriteTo(w io.Writer) (int64, error)
- type Format
- type Level
Constants ¶
Variables ¶
var ( ErrInvalidArgument = errors.New("invalid argument") ErrUnknownLogLevel = errors.New("unknown log level") ErrUnknownLogFormat = errors.New("unknown log format") AllFormats = []string{ string(FormatJSON), string(FormatLogfmt), string(FormatText), } AllLevels = []string{ string(LevelError), string(LevelWarn), string(LevelInfo), string(LevelDebug), } )
var ErrBufferFull = errors.New("buffer is full")
ErrBufferFull indicates that the buffer has reached its maximum capacity.
Functions ¶
func CreateHandlerWithStrings ¶
CreateHandlerWithStrings creates a slog.Handler by strings.
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.