Documentation
¶
Index ¶
- Constants
- func GetModelID(ctx context.Context) (core.ModelID, bool)
- func GetTokenInfo(ctx context.Context) (*core.TokenInfo, bool)
- func SetLogger(l *Logger)
- func WithModelID(ctx context.Context, modelID core.ModelID) context.Context
- func WithTokenInfo(ctx context.Context, info *core.TokenInfo) context.Context
- type Config
- type ConsoleOutput
- type ConsoleOutputOption
- type FileOutput
- type FileOutputOption
- type JSONFormatter
- type LogEntry
- type LogFormatter
- type Logger
- func (l *Logger) Debug(ctx context.Context, format string, args ...interface{})
- func (l *Logger) Error(ctx context.Context, format string, args ...interface{})
- func (l *Logger) Fatal(ctx context.Context, msg string)
- func (l *Logger) Fatalf(ctx context.Context, format string, args ...interface{})
- func (l *Logger) Info(ctx context.Context, format string, args ...interface{})
- func (l *Logger) PromptCompletion(ctx context.Context, prompt, completion string, tokenInfo *core.TokenInfo)
- func (l *Logger) Warn(ctx context.Context, format string, args ...interface{})
- type Output
- type Severity
- type TextFormatter
Constants ¶
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 ¶
GetModelID retrieves ModelID from context.
func GetTokenInfo ¶
GetTokenInfo retrieves TokenInfo from context.
func SetLogger ¶
func SetLogger(l *Logger)
SetLogger allows setting a custom configured logger as the global instance.
func WithModelID ¶
WithModelID adds a ModelID 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) 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 FileOutput ¶ added in v0.21.0
type FileOutput struct {
// contains filtered or unexported fields
}
FileOutput formats logs and writes them to a file.
func NewFileOutput ¶ added in v0.21.0
func NewFileOutput(path string, opts ...FileOutputOption) (*FileOutput, error)
NewFileOutput creates a new file-based logger output.
func (*FileOutput) Close ¶ added in v0.21.0
func (f *FileOutput) Close() error
Close closes the file.
func (*FileOutput) Sync ¶ added in v0.21.0
func (f *FileOutput) Sync() error
Sync flushes any buffered data to the underlying file.
func (*FileOutput) Write ¶ added in v0.21.0
func (f *FileOutput) Write(e LogEntry) error
Write implements the Output interface.
type FileOutputOption ¶ added in v0.21.0
type FileOutputOption func(*FileOutput)
FileOutputOption is a functional option for configuring FileOutput.
func WithBufferSize ¶ added in v0.21.0
func WithBufferSize(size int) FileOutputOption
WithBufferSize sets the internal buffer size for writes.
func WithFormatter ¶ added in v0.21.0
func WithFormatter(formatter LogFormatter) FileOutputOption
WithFormatter sets a custom log formatter.
func WithJSONFormat ¶ added in v0.21.0
func WithJSONFormat(enabled bool) FileOutputOption
WithJSONFormat configures the output to use JSON formatting.
func WithRotation ¶ added in v0.21.0
func WithRotation(maxSizeBytes int64, maxFiles int) FileOutputOption
WithRotation enables log file rotation.
type JSONFormatter ¶ added in v0.21.0
type JSONFormatter struct{}
JSONFormatter implements LogFormatter for JSON output.
func (*JSONFormatter) Format ¶ added in v0.21.0
func (f *JSONFormatter) Format(e LogEntry) string
Format formats a LogEntry as JSON.
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 LogFormatter ¶ added in v0.21.0
LogFormatter defines an interface for formatting log entries.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger provides the core logging functionality.
type Severity ¶
type Severity int32
Severity represents log levels with clear mapping to different stages of LLM operations.
func ParseSeverity ¶ added in v0.37.0
ParseSeverity converts a string to a Severity level. Returns INFO level for unknown strings.
type TextFormatter ¶ added in v0.21.0
type TextFormatter struct {
// Whether to include timestamps in the output
IncludeTimestamp bool
// Whether to include file and line information
IncludeLocation bool
// Whether to include stack traces for errors
IncludeStackTrace bool
}
TextFormatter implements LogFormatter with a simple text format.
func (*TextFormatter) Format ¶ added in v0.21.0
func (f *TextFormatter) Format(e LogEntry) string
Format formats a LogEntry as text.