Documentation
¶
Index ¶
- func CloneContext(ctx context.Context) context.Context
- func CloneContextWithoutTrace(ctx context.Context) context.Context
- func ConfigureFromEnv()
- func Debug(c context.Context, args ...interface{})
- func Debugf(c context.Context, format string, args ...interface{})
- func Error(c context.Context, args ...interface{})
- func ErrorWithFields(c context.Context, err error, fields logrus.Fields)
- func Errorf(c context.Context, format string, args ...interface{})
- func Fatal(c context.Context, args ...interface{})
- func Fatalf(c context.Context, format string, args ...interface{})
- func FormatMessages(messages []LLMMessage) string
- func FormatToolCalls(tcs []LLMToolCallInfo) string
- func GetLogger(c context.Context) *logrus.Entry
- func Info(c context.Context, args ...interface{})
- func Infof(c context.Context, format string, args ...interface{})
- func LLMDebugEnabled() bool
- func LLMDebugLog(ctx context.Context, record *LLMCallRecord)
- func SetLogLevel(level LogLevel)
- func SetOutput(w io.Writer)
- func TruncateRunes(s string, maxRunes int) string
- func Warn(c context.Context, args ...interface{})
- func WarnWithFields(c context.Context, fields Fields, msg string)
- func Warnf(c context.Context, format string, args ...interface{})
- func WithField(c context.Context, key string, value interface{}) context.Context
- func WithFields(c context.Context, fields logrus.Fields) context.Context
- func WithRequestID(c context.Context, requestID string) context.Context
- type CustomFormatter
- type Fields
- type LLMCallRecord
- type LLMMessage
- type LLMToolCallInfo
- type LogLevel
- type RecordSection
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloneContext ¶
CloneContext 复制上下文中的关键信息到新上下文
Which keys survive is decided by types.contextCloneAcrossDetach, which lives next to where context keys are declared so that adding a key and deciding its fate are the same edit. Keeping that decision here instead meant every new key silently defaulted to being dropped.
func CloneContextWithoutTrace ¶
CloneContextWithoutTrace copies the same identity keys as CloneContext but drops the Langfuse *Trace handle and the OpenTelemetry span. Use it for background work that must keep tenant/session identity yet must not attach child spans (Docker Engine HTTP, idle sweeps, image pulls kicked off after a tool has returned) onto the originating chat trace.
func ConfigureFromEnv ¶
func ConfigureFromEnv()
ConfigureFromEnv 重新从环境变量应用日志配置。 这允许在 main() 中加载 .env 后,让 LOG_LEVEL / LOG_PATH / WEKNORA_LOG_FORMAT 立即生效。
func ErrorWithFields ¶
ErrorWithFields 输出带有额外字段的错误级别日志
func FormatMessages ¶
func FormatMessages(messages []LLMMessage) string
FormatMessages formats chat messages into a readable block.
func FormatToolCalls ¶
func FormatToolCalls(tcs []LLMToolCallInfo) string
FormatToolCalls formats response tool calls into a readable block.
func LLMDebugEnabled ¶
func LLMDebugEnabled() bool
LLMDebugEnabled returns true when the dedicated LLM debug log is active.
func LLMDebugLog ¶
func LLMDebugLog(ctx context.Context, record *LLMCallRecord)
LLMDebugLog writes a complete model call record to a per-request log file. All calls sharing the same request_id are appended to the same file.
func SetOutput ¶
SetOutput overrides the internal logger's output destination. Intended for use in tests that need to capture and assert on log content (e.g. verifying secrets are not written out). Restore the original writer (usually os.Stdout) in a defer after the test.
func TruncateRunes ¶
TruncateRunes truncates a string to maxRunes runes, appending "..." if truncated. This is safe for multi-byte UTF-8 characters (e.g. Chinese).
func WarnWithFields ¶
WarnWithFields emits a warning with structured fields. Use this for audit-relevant events (cross-tenant probes, invariant violations) so that log aggregators can index the tenant/resource identifiers without parsing free-form text. Format-string style (Warnf) is appropriate for low-stakes diagnostic messages.
func WithFields ¶
WithFields 向日志中添加多个字段
Types ¶
type CustomFormatter ¶
type Fields ¶
Fields aliases logrus.Fields so callers in other packages can use the short form `logger.Fields{...}` without importing logrus directly.
type LLMCallRecord ¶
type LLMCallRecord struct {
CallType string // "Chat", "Chat Stream", "Embedding", "Rerank", "VLM"
Model string
Duration time.Duration
Sections []RecordSection
Error string
}
LLMCallRecord holds all information for one model API call.
type LLMMessage ¶
type LLMMessage struct {
Role string
Content string
Name string
ToolCallID string
Images []string
ToolCalls []LLMToolCallInfo
}
LLMMessage is a simplified chat message for logging.
type LLMToolCallInfo ¶
LLMToolCallInfo holds tool call info for logging.
type RecordSection ¶
RecordSection is a titled block of text within a call record.