logger

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0, MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneContext

func CloneContext(ctx context.Context) context.Context

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

func CloneContextWithoutTrace(ctx context.Context) context.Context

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 立即生效。

func Debug

func Debug(c context.Context, args ...interface{})

Debug 输出调试级别的日志

func Debugf

func Debugf(c context.Context, format string, args ...interface{})

Debugf 使用格式化字符串输出调试级别的日志

func Error

func Error(c context.Context, args ...interface{})

Error 输出错误级别的日志

func ErrorWithFields

func ErrorWithFields(c context.Context, err error, fields logrus.Fields)

ErrorWithFields 输出带有额外字段的错误级别日志

func Errorf

func Errorf(c context.Context, format string, args ...interface{})

Errorf 使用格式化字符串输出错误级别的日志

func Fatal

func Fatal(c context.Context, args ...interface{})

Fatal 输出致命级别的日志并退出程序

func Fatalf

func Fatalf(c context.Context, format string, args ...interface{})

Fatalf 使用格式化字符串输出致命级别的日志并退出程序

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 GetLogger

func GetLogger(c context.Context) *logrus.Entry

GetLogger 获取日志实例

func Info

func Info(c context.Context, args ...interface{})

Info 输出信息级别的日志

func Infof

func Infof(c context.Context, format string, args ...interface{})

Infof 使用格式化字符串输出信息级别的日志

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 SetLogLevel

func SetLogLevel(level LogLevel)

SetLogLevel 设置日志级别

func SetOutput

func SetOutput(w io.Writer)

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

func TruncateRunes(s string, maxRunes int) string

TruncateRunes truncates a string to maxRunes runes, appending "..." if truncated. This is safe for multi-byte UTF-8 characters (e.g. Chinese).

func Warn

func Warn(c context.Context, args ...interface{})

Warn 输出警告级别的日志

func WarnWithFields

func WarnWithFields(c context.Context, fields Fields, msg string)

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 Warnf

func Warnf(c context.Context, format string, args ...interface{})

Warnf 使用格式化字符串输出警告级别的日志

func WithField

func WithField(c context.Context, key string, value interface{}) context.Context

WithField 向日志中添加一个字段

func WithFields

func WithFields(c context.Context, fields logrus.Fields) context.Context

WithFields 向日志中添加多个字段

func WithRequestID

func WithRequestID(c context.Context, requestID string) context.Context

WithRequestID 在日志中添加请求ID

Types

type CustomFormatter

type CustomFormatter struct {
	ForceColor bool   // 是否强制使用颜色,即使在非终端环境下
	Template   string // 自定义日志格式模板,通过 LOG_FORMAT 环境变量配置,为空则使用内置默认格式
	// contains filtered or unexported fields
}

func (*CustomFormatter) Format

func (f *CustomFormatter) Format(entry *logrus.Entry) ([]byte, error)

type Fields

type Fields = logrus.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

type LLMToolCallInfo struct {
	ID        string
	FuncName  string
	Arguments string
}

LLMToolCallInfo holds tool call info for logging.

type LogLevel

type LogLevel string

LogLevel 日志级别类型

const (
	LevelDebug LogLevel = "debug"
	LevelInfo  LogLevel = "info"
	LevelWarn  LogLevel = "warn"
	LevelError LogLevel = "error"
	LevelFatal LogLevel = "fatal"
)

日志级别常量

type RecordSection

type RecordSection struct {
	Title   string
	Content string
}

RecordSection is a titled block of text within a call record.

Jump to

Keyboard shortcuts

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