writers

package
v1.4.67 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxLogSize default is 500KB - optimized for AI agent consumption
	// At ~150 bytes per log line, this allows approximately 3,300 lines per file
	// which is well within most AI context windows while maintaining readability
	MaxLogSize int64 = 500 * 1024 // 500 KB

	// DefaultMaxBackups keeps 20 backup files by default
	// With 500KB files, this provides ~10MB total log history (20 * 500KB)
	// spanning multiple days of activity while remaining manageable
	DefaultMaxBackups int = 20
)
View Source
const (
	DEFAULT_TTL      = 10 * time.Minute
	CLEANUP_INTERVAL = 1 * time.Minute
	LOG_BUCKET       = "logs"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextWriter deprecated added in v1.4.48

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

Deprecated: ContextWriter is deprecated and will be removed in a future major version. The WithContextWriter method now only adds a correlation ID without creating a ContextWriter. Use SetChannel/SetChannelWithBuffer with correlation ID filtering in consumers instead.

ContextWriter is a lightweight writer that sends log events directly to the global singleton context buffer managed by common.contextbuffer.

func (*ContextWriter) Close added in v1.4.48

func (cw *ContextWriter) Close() error

Close returns nil immediately since there are no resources to clean up. The singleton context buffer lifecycle is managed separately via common.Stop().

func (*ContextWriter) GetFilePath added in v1.4.48

func (cw *ContextWriter) GetFilePath() string

GetFilePath returns an empty string (context writers don't write to files).

func (*ContextWriter) WithLevel added in v1.4.48

func (cw *ContextWriter) WithLevel(level log.Level) IWriter

WithLevel sets the minimum log level for this writer.

func (*ContextWriter) Write added in v1.4.48

func (cw *ContextWriter) Write(p []byte) (n int, err error)

Write implements IWriter by unmarshaling JSON, filtering by log level, and sending to the singleton context buffer.

type FileLogEntry

type FileLogEntry struct {
	Level   string      `json:"level"`
	Message string      `json:"message"`
	Time    string      `json:"time,omitempty"`
	Prefix  string      `json:"prefix,omitempty"`
	Extra   interface{} `json:"-"`
}

FileLogEntry represents a parsed log entry for file writing

type IChannelWriter added in v1.4.52

type IChannelWriter interface {
	IWriter
	Start() error
	Stop() error
	IsRunning() bool
}

func NewChannelWriter added in v1.4.52

func NewChannelWriter(config models.WriterConfiguration, bufferSize int, processor func(models.LogEvent) error) (IChannelWriter, error)

type ILogStore added in v1.4.45

type ILogStore interface {
	// Store adds a log entry to the store (non-blocking, async safe)
	Store(entry models.LogEvent) error

	// GetByCorrelation retrieves all logs for a correlation ID, ordered by timestamp
	GetByCorrelation(correlationID string) ([]models.LogEvent, error)

	// GetByCorrelationWithLevel retrieves logs for a correlation ID filtered by minimum level
	GetByCorrelationWithLevel(correlationID string, minLevel log.Level) ([]models.LogEvent, error)

	// GetSince retrieves all logs since a given timestamp
	GetSince(since time.Time) ([]models.LogEvent, error)

	// GetRecent retrieves the N most recent log entries
	GetRecent(limit int) ([]models.LogEvent, error)

	// GetCorrelationIDs returns all active correlation IDs
	GetCorrelationIDs() []string

	// Close cleans up resources
	Close() error
}

ILogStore defines interface for queryable log storage Implementations can be in-memory only, or backed by persistence (BoltDB)

func NewInMemoryLogStore added in v1.4.45

func NewInMemoryLogStore(config models.WriterConfiguration) (ILogStore, error)

NewInMemoryLogStore creates a new in-memory log store

type IMemoryWriter added in v1.4.16

type IMemoryWriter interface {
	IWriter

	// GetEntries retrieves all log entries for a specific correlation ID
	GetEntries(correlationID string) (map[string]string, error)

	// GetAllEntries retrieves all log entries across all correlation IDs
	GetAllEntries() (map[string]string, error)

	// GetEntriesWithLevel retrieves log entries filtered by minimum log level
	GetEntriesWithLevel(correlationID string, minLevel log.Level) (map[string]string, error)

	// GetStoredCorrelationIDs returns all correlation IDs that have stored logs
	GetStoredCorrelationIDs() []string

	// GetEntriesWithLimit retrieves the most recent log entries up to the specified limit
	GetEntriesWithLimit(limit int) (map[string]string, error)

	// GetEntriesSince retrieves all log entries since a given timestamp (for WebSocket queries)
	GetEntriesSince(since time.Time) ([]models.LogEvent, error)

	// GetStore returns the underlying log store for use with other writers
	GetStore() ILogStore

	// Close closes the memory writer and any underlying resources
	Close() error
}

IMemoryWriter extends IWriter with memory-specific operations

func MemoryWriter

func MemoryWriter(config models.WriterConfiguration) IMemoryWriter

MemoryWriter creates a new memory writer backed by a log store Note: This should be used alongside LogStoreWriter LogStoreWriter handles writes, MemoryWriter handles queries

type IWriter added in v1.4.14

type IWriter interface {
	WithLevel(level log.Level) IWriter
	Write(p []byte) (n int, err error)
	GetFilePath() string // Returns the file path if this is a file writer, empty string otherwise
	Close() error
}

func ConsoleWriter

func ConsoleWriter(config models.WriterConfiguration) IWriter

ConsoleWriter creates a new ConsoleWriter with phuslu backend

func FileWriter

func FileWriter(config models.WriterConfiguration) IWriter

func LogStoreWriter added in v1.4.45

func LogStoreWriter(store ILogStore, config models.WriterConfiguration) IWriter

LogStoreWriter creates a new writer that stores logs in the provided ILogStore

func NewContextWriter added in v1.4.48

func NewContextWriter(config models.WriterConfiguration) IWriter

NewContextWriter creates a new ContextWriter.

type StoredLogEntry added in v1.4.16

type StoredLogEntry struct {
	LogEvent  models.LogEvent `json:"log_event"`
	ExpiresAt time.Time       `json:"expires_at"`
}

StoredLogEntry wraps a log event with expiration metadata

Jump to

Keyboard shortcuts

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