Documentation
¶
Overview ¶
Package logger 提供 Hexagon AI Agent 框架的日志工具
Logger 封装了 toolkit/util/logger,并添加了 Agent 相关的上下文字段支持。 支持自动从 context 中提取 agent_id, session_id, trace_id, span_id 等字段。
Index ¶
- Variables
- func AgentID(id string) slog.Attr
- func AgentIDFromContext(ctx context.Context) string
- func CompletionTokens(count int) slog.Attr
- func ComponentFromContext(ctx context.Context) string
- func ContextWithAgentID(ctx context.Context, agentID string) context.Context
- func ContextWithComponent(ctx context.Context, component string) context.Context
- func ContextWithSessionID(ctx context.Context, sessionID string) context.Context
- func ContextWithSpanID(ctx context.Context, spanID string) context.Context
- func ContextWithTraceID(ctx context.Context, traceID string) context.Context
- func Debug(msg string, args ...any)
- func DebugContext(ctx context.Context, msg string, args ...any)
- func Error(msg string, args ...any)
- func ErrorContext(ctx context.Context, msg string, args ...any)
- func Info(msg string, args ...any)
- func InfoContext(ctx context.Context, msg string, args ...any)
- func Init(cfg *Config) error
- func Iteration(n int) slog.Attr
- func Model(name string) slog.Attr
- func PromptTokens(count int) slog.Attr
- func SessionID(id string) slog.Attr
- func SessionIDFromContext(ctx context.Context) string
- func SetDefault(l Logger)
- func SetLevel(level string)
- func SpanID(id string) slog.Attr
- func SpanIDFromContext(ctx context.Context) string
- func Tokens(count int) slog.Attr
- func ToolName(name string) slog.Attr
- func TraceIDFromContext(ctx context.Context) string
- func Warn(msg string, args ...any)
- func WarnContext(ctx context.Context, msg string, args ...any)
- type AgentLogger
- func (l *AgentLogger) Close() error
- func (l *AgentLogger) Debug(msg string, args ...any)
- func (l *AgentLogger) DebugContext(ctx context.Context, msg string, args ...any)
- func (l *AgentLogger) Error(msg string, args ...any)
- func (l *AgentLogger) ErrorContext(ctx context.Context, msg string, args ...any)
- func (l *AgentLogger) Info(msg string, args ...any)
- func (l *AgentLogger) InfoContext(ctx context.Context, msg string, args ...any)
- func (l *AgentLogger) Inner() *tklogger.Logger
- func (l *AgentLogger) SetLevel(level string)
- func (l *AgentLogger) Warn(msg string, args ...any)
- func (l *AgentLogger) WarnContext(ctx context.Context, msg string, args ...any)
- func (l *AgentLogger) With(args ...any) Logger
- func (l *AgentLogger) WithContext(ctx context.Context) Logger
- type Config
- type FileConfig
- type Logger
Constants ¶
This section is empty.
Variables ¶
var ( String = tklogger.String Int = tklogger.Int Int64 = tklogger.Int64 Uint64 = tklogger.Uint64 Float64 = tklogger.Float64 Bool = tklogger.Bool Time = tklogger.Time Duration = tklogger.Duration Any = tklogger.Any Group = tklogger.Group Err = tklogger.Err TraceID = tklogger.TraceID Latency = tklogger.Latency )
重新导出 toolkit logger 的常用属性函数
Functions ¶
func AgentIDFromContext ¶
AgentIDFromContext 从 context 中获取 Agent ID
func CompletionTokens ¶
CompletionTokens 创建 completion_tokens 属性
func ComponentFromContext ¶
ComponentFromContext 从 context 中获取组件名称
func ContextWithAgentID ¶
ContextWithAgentID 将 Agent ID 添加到 context
func ContextWithComponent ¶
ContextWithComponent 将组件名称添加到 context
func ContextWithSessionID ¶
ContextWithSessionID 将 Session ID 添加到 context
func ContextWithSpanID ¶
ContextWithSpanID 将 Span ID 添加到 context
func ContextWithTraceID ¶
ContextWithTraceID 将 Trace ID 添加到 context
func DebugContext ¶
DebugContext 使用默认 Logger 记录带 context 的调试日志
func ErrorContext ¶
ErrorContext 使用默认 Logger 记录带 context 的错误日志
func InfoContext ¶
InfoContext 使用默认 Logger 记录带 context 的信息日志
func SessionIDFromContext ¶
SessionIDFromContext 从 context 中获取 Session ID
func SpanIDFromContext ¶
SpanIDFromContext 从 context 中获取 Span ID
func TraceIDFromContext ¶
TraceIDFromContext 从 context 中获取 Trace ID
Types ¶
type AgentLogger ¶
type AgentLogger struct {
// contains filtered or unexported fields
}
AgentLogger 基于 toolkit logger 的 Agent 日志实现
func NewWithLogger ¶
func NewWithLogger(l *tklogger.Logger) *AgentLogger
NewWithLogger 从已有的 toolkit logger 创建 AgentLogger
func (*AgentLogger) DebugContext ¶
func (l *AgentLogger) DebugContext(ctx context.Context, msg string, args ...any)
DebugContext 记录带 context 的调试日志
func (*AgentLogger) ErrorContext ¶
func (l *AgentLogger) ErrorContext(ctx context.Context, msg string, args ...any)
ErrorContext 记录带 context 的错误日志
func (*AgentLogger) InfoContext ¶
func (l *AgentLogger) InfoContext(ctx context.Context, msg string, args ...any)
InfoContext 记录带 context 的信息日志
func (*AgentLogger) Inner ¶
func (l *AgentLogger) Inner() *tklogger.Logger
Inner 返回底层的 toolkit logger
func (*AgentLogger) WarnContext ¶
func (l *AgentLogger) WarnContext(ctx context.Context, msg string, args ...any)
WarnContext 记录带 context 的警告日志
func (*AgentLogger) WithContext ¶
func (l *AgentLogger) WithContext(ctx context.Context) Logger
WithContext 从 context 中提取上下文信息创建子 Logger
type Logger ¶
type Logger interface {
// Debug 记录调试日志
Debug(msg string, args ...any)
// Info 记录信息日志
Info(msg string, args ...any)
// Warn 记录警告日志
Warn(msg string, args ...any)
// Error 记录错误日志
Error(msg string, args ...any)
// DebugContext 记录带 context 的调试日志
DebugContext(ctx context.Context, msg string, args ...any)
// InfoContext 记录带 context 的信息日志
InfoContext(ctx context.Context, msg string, args ...any)
// WarnContext 记录带 context 的警告日志
WarnContext(ctx context.Context, msg string, args ...any)
// ErrorContext 记录带 context 的错误日志
ErrorContext(ctx context.Context, msg string, args ...any)
// With 创建带有额外字段的子 Logger
With(args ...any) Logger
// WithContext 从 context 中提取上下文信息创建子 Logger
WithContext(ctx context.Context) Logger
// SetLevel 动态设置日志级别
SetLevel(level string)
}
Logger 是 Hexagon 框架的日志接口