glog

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

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

Logger 是基于 Google glog 的日志适配器。

glog 是 Google 开源的 leveled logging 库,广泛用于 gRPC、Kubernetes 等 基础设施项目。它按级别分文件输出日志,支持 V() 细粒度日志级别控制。

注意:glog 不支持原生的结构化键值对,keyvals 会被格式化为 "key=value" 追加到消息中。

Example:

logger := glog.NewLogger()
defer logger.Close()
logger.Info(ctx, "server started", "port", 8080)

func NewLogger

func NewLogger() *Logger

NewLogger 创建一个 glog 日志记录器。 注意:glog 需要在 main() 中调用 flag.Parse() 才能正常工作。

func (*Logger) Close

func (l *Logger) Close() error

Close 刷新 glog 缓冲区。

func (*Logger) Debug

func (l *Logger) Debug(_ context.Context, msg string, keyvals ...any)

Debug 输出 DEBUG 级别日志(映射为 glog.V(1))。

func (*Logger) Enabled

func (l *Logger) Enabled(_ bLogger.Level) bool

Enabled 报告给定级别是否会被输出。 glog 的级别由命令行 flag(-v, -stderrthreshold)控制,此处保守返回 true。

func (*Logger) Error

func (l *Logger) Error(_ context.Context, msg string, keyvals ...any)

Error 输出 ERROR 级别日志。

func (*Logger) Info

func (l *Logger) Info(_ context.Context, msg string, keyvals ...any)

Info 输出 INFO 级别日志。

func (*Logger) Warn

func (l *Logger) Warn(_ context.Context, msg string, keyvals ...any)

Warn 输出 WARN 级别日志(映射为 glog.Warning)。

func (*Logger) With

func (l *Logger) With(keyvals ...any) bLogger.Logger

With 返回附加了指定 key-value 对的新 Logger 实例。 glog 不支持原生 With,通过内部 extra 切片模拟。

Jump to

Keyboard shortcuts

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