log

package
v0.0.0-...-4f9d474 Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyRequestID   string = "requestID"
	KeyUsername    string = "username"
	KeyWatcherName string = "watcher"
)

定义日志公共字段.

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{})

func Debugw

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

Debugw 输出 debug 级别的日志.

func Errorf

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

func Errorw

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

Errorw 输出 error 级别的日志.

func Fatalf

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

func Fatalw

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

Fatalw 输出 fatal 级别的日志.

func Infof

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

func Infow

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

Infow 输出 info 级别的日志.

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{})

func Panicw

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

Panicw 输出 panic 级别的日志.

func Sync

func Sync()

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

func Warnf

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

func Warnw

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

Warnw 输出 warning 级别的日志.

Types

type Logger

type Logger interface {
	Debugw(msg string, keysAndValues ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	Warnw(msg string, keysAndValues ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
	Panicw(msg string, keysAndValues ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})
	Sync()
}

Logger 定义了 skeleton 项目的日志接口,该接口只包含了支持的日志记录方法.

type Options

type Options struct {
	Level             string   `json:"level"              mapstructure:"level"`              // 指定日志级别,可选值:debug, info, warn, error, dpanic, panic, fatal
	DisableCaller     bool     `json:"disable-caller"     mapstructure:"disable-caller"`     // 是否禁止 caller,如果开启会在日志中显示调用日志所在的文件和行号
	DisableStacktrace bool     `json:"disable-stacktrace" mapstructure:"disable-stacktrace"` // 是否禁止在 panic 及以上级别打印堆栈信息
	Format            string   `json:"format"             mapstructure:"format"`             // 指定日志格式,可选值:console, json
	EnableColor       bool     `json:"enable-color"       mapstructure:"enable-color"`       // 是否进行颜色区分
	OutputPaths       []string `json:"output-paths"       mapstructure:"output-paths"`       // 指定日志输出位置
	ErrorOutputPaths  []string `json:"error-output-paths" mapstructure:"error-output-paths"` // 指定错误日志输出位置
	Development       bool     `json:"development"        mapstructure:"development"`        // 是否处于开发模式
	Name              string   `json:"name"               mapstructure:"name"`               // 指定日志名称
}

Options 包含与日志相关的配置项.

func NewOptions

func NewOptions() *Options

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

func (*Options) AddFlags

func (o *Options) AddFlags(fs *pflag.FlagSet)

func (*Options) Validate

func (o *Options) Validate() []error

Jump to

Keyboard shortcuts

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