logging

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package logging 写入 Runtime 诊断信息与操作日志。

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidArgument 表示调用参数不满足 logging 契约。
	ErrInvalidArgument = errors.New("logging argument is invalid")
	// ErrInvalidLevel 表示日志级别不在冻结集合内。
	ErrInvalidLevel = errors.New("logging level is invalid")
	// ErrInvalidRetention 表示保留策略字段不是正数。
	ErrInvalidRetention = errors.New("logging retention is invalid")
	// ErrInvalidTime 表示注入时钟返回零值。
	ErrInvalidTime = errors.New("logging clock returned invalid time")
	// ErrEncodeEntry 表示 details 或完整 entry 无法编码。
	ErrEncodeEntry = errors.New("encode log entry")
	// ErrClosed 表示 Logger 已经关闭。
	ErrClosed = errors.New("logger is closed")
)

Functions

This section is empty.

Types

type Level

type Level string

Level 表示 Runtime 本地日志级别。

const (
	LevelDebug Level = "debug"
	LevelInfo  Level = "info"
	LevelWarn  Level = "warn"
	LevelError Level = "error"
)

func (Level) String

func (l Level) String() string

String 返回稳定的日志级别字面量。

func (Level) Valid

func (l Level) Valid() bool

Valid 报告日志级别是否属于冻结集合。

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger 将同一 Runtime 操作的诊断与操作记录写入受管本地 sink。

func New

func New(
	ctx context.Context,
	layout *config.Layout,
	stderr io.Writer,
	command string,
	operationID string,
	options ...Option,
) (*Logger, error)

New 创建并立即打开当前本地日期的 Runtime 日志文件。

func (*Logger) Close

func (l *Logger) Close() error

Close 按 writer、RuntimeLogFiles 的顺序幂等释放 Logger 自有资源。

func (*Logger) Diagnostic

func (l *Logger) Diagnostic(
	ctx context.Context,
	level Level,
	message string,
	details map[string]any,
) (WriteResult, error)

Diagnostic 将 Runtime 诊断同步写入活动 JSONL 文件和 stderr。

func (*Logger) LogPath

func (l *Logger) LogPath() string

LogPath 返回最后一个成功打开的活动日志绝对路径。

func (*Logger) Record

func (l *Logger) Record(
	ctx context.Context,
	level Level,
	message string,
	details map[string]any,
) (WriteResult, error)

Record 将操作记录同步写入活动 JSONL 文件。

type Option

type Option func(*options) error

Option 配置 Logger 构造参数。

func WithClock

func WithClock(clock func() time.Time) Option

WithClock 注入返回本地时间的时钟。

func WithRetention

func WithRetention(policy RetentionPolicy) Option

WithRetention 按值复制保留策略。

type RetentionPolicy

type RetentionPolicy struct {
	MaxAgeDays         int
	MaxFilesPerCommand int
}

RetentionPolicy 定义本地日历日和每个命令的日志文件上限。

func DefaultRetentionPolicy

func DefaultRetentionPolicy() RetentionPolicy

DefaultRetentionPolicy 返回冻结的 30 日、每命令 30 文件策略。

type WriteResult

type WriteResult struct {
	FileWritten   bool
	StderrWritten bool
	Rotated       bool
}

WriteResult 精确描述一次调用已经对哪些 sink 产生字节副作用。

Jump to

Keyboard shortcuts

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