Documentation
¶
Overview ¶
Package logging 提供 CLI、MCP、SDK 共用的 slog 层:ctx 中的调用信息、属性键常量和 可配置的 text/JSON handler。
WithCall 由执行边界写入 operation 与 call_id,之后同一 ctx 上的日志都会附带这些 字段;WithOperation 只登记 SDK 操作名。
包的组成:New 创建带调用上下文与脱敏行为的 handler,From 从 ctx 取 logger, AttrMethod 等常量是各方共用的字段名,WithCall 与 WithOperation 负责绑定。
origin.go 保存 SDK 错误的创建位置,供执行边界读取而无需扩展 SDK 公开方法集。
transport.go 从标准库 typed cause 提取安全的传输诊断,绝不读取错误文本或 URL。
Index ¶
- Constants
- func Discard() *slog.Logger
- func From(ctx context.Context) *slog.Logger
- func HasLogger(ctx context.Context) bool
- func New(w io.Writer, level, format string) (*slog.Logger, error)
- func OperationAttr(ctx context.Context) slog.Attr
- func OriginAttr(err error) []slog.Attr
- func TransportAttrs(err error) []slog.Attr
- func WithCall(ctx context.Context, logger *slog.Logger, operation, callID string) context.Context
- func WithOperation(ctx context.Context, operation string) context.Context
- type ErrorOrigin
- type State
Constants ¶
const ( // FormatText 输出带来源位置与人读错误链的文本日志。 FormatText = "text" // FormatJSON 输出单行 JSON 日志对象。 FormatJSON = "json" )
const ( AttrOrigin = "origin" AttrMethod = "method" AttrHost = "host" AttrPath = "path" AttrStatus = "status" AttrDuration = "duration" AttrAttempt = "attempt" AttrWait = "wait" AttrSDKOperation = "sdk_operation" AttrError = "error" AttrCount = "count" AttrStage = "stage" AttrOperation = "operation" AttrCallID = "call_id" AttrReason = "reason" )
AttrMethod 等常量是日志属性键,SDK 传输层、执行边界和 JSON 输出共用这些字段名。
const ( AttrNetworkOperation = "op" AttrNetwork = "net" AttrAddress = "address" AttrErrno = "errno" )
AttrNetworkOperation 等键标记 typed 传输原因的安全字段。
Variables ¶
This section is empty.
Functions ¶
func OperationAttr ¶ added in v1.3.0
OperationAttr 返回 SDK 操作名属性;没有登记时为空字符串。
func OriginAttr ¶ added in v1.3.0
OriginAttr 从错误链取得 SDK 的私有位置;不呈现任何底层错误文本。
func TransportAttrs ¶ added in v1.3.0
TransportAttrs 提取操作、网络、远端地址与已知 errno 名。 地址只接受标准库 IP 地址类型;未知 errno 不使用 Error 文本代替名称。
Types ¶
type ErrorOrigin ¶ added in v1.3.0
type ErrorOrigin struct {
// contains filtered or unexported fields
}
ErrorOrigin 以未导出方法跨包传递位置;SDK 通过私有别名嵌入,JSON 无可序列化字段。
func CaptureErrorOrigin ¶ added in v1.3.0
func CaptureErrorOrigin() ErrorOrigin
CaptureErrorOrigin 跳过 SDK 构造函数及产品 errors.go 中的分类包装。