xzap

package
v0.0.0-...-f274578 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLoger

func GetLoger() *zap.Logger

func NewCtxZapLoger

func NewCtxZapLoger(optApply ...OptionFunc)

初始化zap日志配置

Types

type CtxZapLogger

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

func GetCtxZapLoger

func GetCtxZapLoger() *CtxZapLogger

func (*CtxZapLogger) GetCoresOption

func (l *CtxZapLogger) GetCoresOption() zap.Option

设置启用日志类型

func (*CtxZapLogger) GetCtx

func (l *CtxZapLogger) GetCtx(ctx context.Context) *zap.Logger

获取带ctx的loger

func (*CtxZapLogger) GetLogLevel

func (l *CtxZapLogger) GetLogLevel() (level zapcore.Level)

从配置文件中获取日志配置等级

func (*CtxZapLogger) SetFileSyncer

func (l *CtxZapLogger) SetFileSyncer()

设置zap.AddSync

func (*CtxZapLogger) Sync

func (l *CtxZapLogger) Sync() error

zap底层 API 可以设置缓存,一般主进程退出前使用defer Sync()将缓存同步到文件中

func (*CtxZapLogger) WithContext

func (l *CtxZapLogger) WithContext(ctx context.Context) *zap.Logger

向logger增加ctx

func (*CtxZapLogger) WithContextAndFields

func (l *CtxZapLogger) WithContextAndFields(ctx context.Context, field ...zap.Field) (context.Context, *zap.Logger)

向logger增加ctx+日志字段

type Option

type Option struct {
	Tags []string //TODO:记录zap的fileds

	Development        bool
	LogFileDir         string
	AppName            string
	MaxSize            int
	MaxBackups         int
	MaxAge             int
	Level              string
	EnableCompress     bool
	EnableWriteFile    bool
	EnableWriteConsole bool
}

type OptionFunc

type OptionFunc func(*Option)

func SetAppName

func SetAppName(appName string) OptionFunc

func SetDevelopment

func SetDevelopment(development bool) OptionFunc

func SetLevel

func SetLevel(level string) OptionFunc

func SetLogCompress

func SetLogCompress(isOn bool) OptionFunc

func SetLogFileDir

func SetLogFileDir(logFileDir string) OptionFunc

func SetMaxAge

func SetMaxAge(maxAge int) OptionFunc

func SetMaxBackups

func SetMaxBackups(maxBackups int) OptionFunc

func SetMaxSize

func SetMaxSize(maxSize int) OptionFunc

func SetWriteConsole

func SetWriteConsole(writeConsole bool) OptionFunc

func SetWriteFile

func SetWriteFile(writeFile bool) OptionFunc

Jump to

Keyboard shortcuts

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