internal

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ColorReset 重置 ANSI 颜色。
	ColorReset = "\033[0m"
	// ColorYellow 黄色(耗时/提示)。
	ColorYellow = "\033[33m"
	// ColorBlueBold 蓝色加粗(字段高亮)。
	ColorBlueBold = "\033[34;1m"
	// ColorRedBold 红色加粗(错误高亮)。
	ColorRedBold = "\033[31;1m"

	// LogTypeMongo 为日志类型标识(供下游聚合检索)。
	LogTypeMongo = 6
	// ResultSuccess 为成功执行的结果标记。
	ResultSuccess = "success"

	// TraceId 为从 metadata 读取 trace id 的 key。
	TraceId = "trace-id"
	// UserId 为从 metadata 读取 user id 的 key。
	UserId = "user-id"
	// AppId 为从 metadata 读取 app id 的 key。
	AppId = "app-id"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Conf

type Conf struct {
	// Console 控制是否输出到控制台。
	Console bool
	// SlowThreshold 为慢查询阈值。
	SlowThreshold time.Duration
	// Colorful 控制是否启用彩色输出。
	Colorful bool
	// Database 为库名字段,用于检索与聚合。
	Database string
	// LogLevel 为日志级别。
	LogLevel LogLevel
}

Conf 为 logger 的配置。

type Interface

type Interface interface {
	// Trace 记录一次命令的执行信息。
	Trace(ctx context.Context, id int64, elapsed time.Duration, smt string, err string)
}

Interface 约束 logger 需要提供的能力。

func NewLogger

func NewLogger(conf *Conf, handle func([]byte)) Interface

NewLogger 构造一个新的 logger,并按配置决定输出模板。

type LogLevel

type LogLevel int

LogLevel 定义日志级别枚举。

const (
	Silent LogLevel = iota + 1 // Silent 表示不记录任何日志。
	Error                      // Error 表示仅记录错误日志。
	Warn                       // Warn 表示记录慢查询与错误日志。
	Info                       // Info 表示记录所有日志。
)

Jump to

Keyboard shortcuts

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