log

package
v0.0.5-beta2 Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: Apache-2.0 Imports: 7 Imported by: 2

Documentation

Index

Constants

View Source
const (
	KeyRequestID string = "requestID"
)

Variables

This section is empty.

Functions

func C

func C(ctx context.Context) *zapLogger

C 解析传入的 context,尝试提取关注的键值,并添加到 zap.Logger 结构化日志中.

func Debugf

func Debugf(format string, v ...interface{})

Debugf method output debug level log.

func Debugw

func Debugw(msg string, keysAndValues ...interface{})

Debugw method output debug level log.

func Errorf

func Errorf(format string, v ...interface{})

Errorf method output error level log.

func Errorw

func Errorw(msg string, keysAndValues ...interface{})

Errorw method output error level log.

func Fatalf

func Fatalf(format string, v ...interface{})

Fatalf method output fatal level log.

func Fatalw

func Fatalw(msg string, keysAndValues ...interface{})

Fatalw method output Fatalw level log.

func Infof

func Infof(format string, v ...interface{})

Infof method output info level log.

func Infow

func Infow(msg string, keysAndValues ...interface{})

Infow method output info level log.

func Init

func Init(opts *Options)

Init 使用指定的选项初始化 Logger.

func NewLogger

func NewLogger(opts *Options) *zapLogger

NewLogger 根据传入的 opts 创建 Logger.

func Panicf

func Panicf(format string, v ...interface{})

Panicf method output panic level log and shutdown application.

func Panicw

func Panicw(msg string, keysAndValues ...interface{})

Panicw method output panic level log.

func Sync

func Sync()

Sync 调用底层 zap.Logger 的 Sync 方法,将缓存中的日志刷新到磁盘文件中. 主程序需要在退出前调用 Sync.

func Warnf

func Warnf(format string, v ...interface{})

Warnf method output warning level log.

func Warnw

func Warnw(msg string, keysAndValues ...interface{})

Warnw method output warning level log.

Types

type Logger

type Logger interface {
	Debugf(format string, v ...interface{})
	Debugw(msg string, keysAndValues ...interface{})
	Infof(format string, v ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	Warnf(format string, v ...interface{})
	Warnw(msg string, keysAndValues ...interface{})
	Errorf(format string, v ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
	Panicf(format string, v ...interface{})
	Panicw(msg string, keysAndValues ...interface{})
	Fatalf(format string, v ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})
	Sync()
}

type Options

type Options struct {
	// 是否开启 caller,如果开启会在日志中显示调用日志所在的文件和行号
	DisableCaller bool
	// 是否禁止在 panic 及以上级别打印堆栈信息
	DisableStacktrace bool
	// 指定日志级别,可选值:debug, info, warn, error, dpanic, panic, fatal
	Level string
	// 指定日志显示格式,可选值:console, json
	Format string
	// 指定日志输出位置
	OutputPaths []string
}

func NewOptions

func NewOptions() *Options

NewOptions 创建一个带有默认参数的 Options 对象.

Jump to

Keyboard shortcuts

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