logging

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(source, format string, args ...interface{})

func Error

func Error(source, format string, args ...interface{})

func Info

func Info(source, format string, args ...interface{})

Convenience functions for global logger

func Warn

func Warn(source, format string, args ...interface{})

Types

type LogEntry

type LogEntry struct {
	Timestamp time.Time `json:"timestamp"`
	Level     LogLevel  `json:"level"`
	Message   string    `json:"message"`
	Source    string    `json:"source,omitempty"`
}

LogEntry represents a single log entry

type LogLevel

type LogLevel string

LogLevel represents the severity of a log entry

const (
	LevelDebug LogLevel = "DEBUG"
	LevelInfo  LogLevel = "INFO"
	LevelWarn  LogLevel = "WARN"
	LevelError LogLevel = "ERROR"
)

type RingBuffer

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

RingBuffer is a thread-safe circular buffer for log entries

func GetGlobalLogger

func GetGlobalLogger() *RingBuffer

GetGlobalLogger returns the global logger instance

func NewRingBuffer

func NewRingBuffer(size int) *RingBuffer

NewRingBuffer creates a new ring buffer with the specified capacity

func (*RingBuffer) Add

func (rb *RingBuffer) Add(entry LogEntry)

Add appends a new log entry to the buffer

func (*RingBuffer) AddLog

func (rb *RingBuffer) AddLog(level LogLevel, source, format string, args ...interface{})

AddLog is a convenience method to add a log with level and message

func (*RingBuffer) Clear

func (rb *RingBuffer) Clear()

Clear removes all entries from the buffer

func (*RingBuffer) Debug

func (rb *RingBuffer) Debug(source, format string, args ...interface{})

Debug logs a debug message

func (*RingBuffer) Error

func (rb *RingBuffer) Error(source, format string, args ...interface{})

Error logs an error message

func (*RingBuffer) GetAll

func (rb *RingBuffer) GetAll() []LogEntry

GetAll returns all log entries in chronological order

func (*RingBuffer) GetByLevel

func (rb *RingBuffer) GetByLevel(levels ...LogLevel) []LogEntry

GetByLevel returns log entries filtered by level

func (*RingBuffer) GetLast

func (rb *RingBuffer) GetLast(n int) []LogEntry

GetLast returns the last n log entries

func (*RingBuffer) Info

func (rb *RingBuffer) Info(source, format string, args ...interface{})

Info logs an info message

func (*RingBuffer) Warn

func (rb *RingBuffer) Warn(source, format string, args ...interface{})

Warn logs a warning message

Jump to

Keyboard shortcuts

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