logging

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ModelIDKey is used to store/retrieve ModelID from context.
	ModelIDKey contextKey = "model_id"

	// TokenInfoKey is used to store/retrieve token usage information.
	TokenInfoKey contextKey = "token_info"
)

Variables

This section is empty.

Functions

func GetModelID

func GetModelID(ctx context.Context) (core.ModelID, bool)

GetModelID retrieves ModelID from context.

func GetTokenInfo

func GetTokenInfo(ctx context.Context) (*core.TokenInfo, bool)

GetTokenInfo retrieves TokenInfo from context.

func SetLogger

func SetLogger(l *Logger)

SetLogger allows setting a custom configured logger as the global instance.

func WithModelID

func WithModelID(ctx context.Context, modelID core.ModelID) context.Context

WithModelID adds a ModelID to the context.

func WithTokenInfo

func WithTokenInfo(ctx context.Context, info *core.TokenInfo) context.Context

WithTokenInfo adds TokenInfo to the context.

Types

type Config

type Config struct {
	Severity      Severity
	Outputs       []Output
	SampleRate    uint32
	DefaultFields map[string]interface{}
}

Config allows flexible logger configuration.

type ConsoleOutput

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

ConsoleOutput formats logs for human readability.

func NewConsoleOutput

func NewConsoleOutput(useStderr bool, opts ...ConsoleOutputOption) *ConsoleOutput

func (*ConsoleOutput) Close

func (c *ConsoleOutput) Close() error

Close cleans up any resources.

func (*ConsoleOutput) Sync

func (c *ConsoleOutput) Sync() error

func (*ConsoleOutput) Write

func (o *ConsoleOutput) Write(e LogEntry) error

type ConsoleOutputOption

type ConsoleOutputOption func(*ConsoleOutput)

func WithColor

func WithColor(enabled bool) ConsoleOutputOption

type LogEntry

type LogEntry struct {
	// Standard fields
	Time     int64
	Severity Severity
	Message  string
	File     string
	Line     int
	Function string
	TraceID  string // Added trace ID field

	// LLM-specific fields
	ModelID   string          // The LLM model being used
	TokenInfo *core.TokenInfo // Token usage information
	Latency   int64           // Operation duration in milliseconds
	Cost      float64         // Operation cost in dollars

	// General structured data
	Fields map[string]interface{}
}

LogEntry represents a structured log record with fields particularly relevant to LLM operations.

type Logger

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

Logger provides the core logging functionality.

func GetLogger

func GetLogger() *Logger

GetLogger returns the global logger instance.

func NewLogger

func NewLogger(cfg Config) *Logger

NewLogger creates a new logger with the given configuration.

func (*Logger) Debug

func (l *Logger) Debug(ctx context.Context, format string, args ...interface{})

Regular severity-based logging methods.

func (*Logger) Error

func (l *Logger) Error(ctx context.Context, format string, args ...interface{})

func (*Logger) Info

func (l *Logger) Info(ctx context.Context, format string, args ...interface{})

func (*Logger) PromptCompletion

func (l *Logger) PromptCompletion(ctx context.Context, prompt, completion string, tokenInfo *core.TokenInfo)

LLM-specific logging methods.

func (*Logger) Warn

func (l *Logger) Warn(ctx context.Context, format string, args ...interface{})

type Output

type Output interface {
	Write(LogEntry) error
	Sync() error
	Close() error
}

Output interface allows for different logging destinations.

type Severity

type Severity int32

Severity represents log levels with clear mapping to different stages of LLM operations.

const (
	DEBUG Severity = iota
	INFO
	WARN
	ERROR
	FATAL
)

func (Severity) String

func (s Severity) String() string

String provides human-readable severity levels.

Jump to

Keyboard shortcuts

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