logbuffer

package
v0.44.4 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: Unlicense Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCurrentLevel

func GetCurrentLevel() string

GetCurrentLevel returns the current log level string

func Init

func Init(size int)

Init initializes the global log buffer

func SetCurrentLevel

func SetCurrentLevel(level string) string

SetCurrentLevel sets the current log level and returns it

Types

type Buffer

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

Buffer is a thread-safe ring buffer for log entries

var GlobalBuffer *Buffer

Global buffer instance

func NewBuffer

func NewBuffer(size int) *Buffer

NewBuffer creates a new ring buffer with the specified size

func (*Buffer) Add

func (b *Buffer) Add(entry LogEntry)

Add adds a log entry to the buffer

func (*Buffer) Clear

func (b *Buffer) Clear()

Clear removes all entries from the buffer

func (*Buffer) Count

func (b *Buffer) Count() int

Count returns the number of entries in the buffer

func (*Buffer) Get

func (b *Buffer) Get(offset, limit int) []LogEntry

Get returns log entries, newest first offset is the number of entries to skip from the newest limit is the maximum number of entries to return

type BufferedWriter

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

BufferedWriter wraps an io.Writer and captures log entries

func NewBufferedWriter

func NewBufferedWriter(original io.Writer, buffer *Buffer) *BufferedWriter

NewBufferedWriter creates a new BufferedWriter

func (*BufferedWriter) Write

func (w *BufferedWriter) Write(p []byte) (n int, err error)

Write implements io.Writer

type LogEntry

type LogEntry struct {
	ID        int64     `json:"id"`
	Timestamp time.Time `json:"timestamp"`
	Level     string    `json:"level"`
	Message   string    `json:"message"`
	File      string    `json:"file,omitempty"`
	Line      int       `json:"line,omitempty"`
}

LogEntry represents a single log entry

Source Files

  • buffer.go
  • writer.go

Jump to

Keyboard shortcuts

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