logger

package
v0.0.0-...-6f9dc6e Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Skip        = zap.Skip
	Binary      = zap.Binary
	Bool        = zap.Bool
	Boolp       = zap.Boolp
	ByteString  = zap.ByteString
	Complex128  = zap.Complex128
	Complex128p = zap.Complex128p
	Complex64   = zap.Complex64
	Complex64p  = zap.Complex64p
	Float64     = zap.Float64
	Float64p    = zap.Float64p
	Float32     = zap.Float32
	Float32p    = zap.Float32p
	Int         = zap.Int
	Intp        = zap.Intp
	Int64       = zap.Int64
	Int64p      = zap.Int64p
	Int32       = zap.Int32
	Int32p      = zap.Int32p
	Int16       = zap.Int16
	Int16p      = zap.Int16p
	Int8        = zap.Int8
	Int8p       = zap.Int8p
	String      = zap.String
	Stringp     = zap.Stringp
	Uint        = zap.Uint
	Uintp       = zap.Uintp
	Uint64      = zap.Uint64
	Uint64p     = zap.Uint64p
	Uint32      = zap.Uint32
	Uint32p     = zap.Uint32p
	Uint16      = zap.Uint16
	Uint16p     = zap.Uint16p
	Uint8       = zap.Uint8
	Uint8p      = zap.Uint8p
	Uintptr     = zap.Uintptr
	Uintptrp    = zap.Uintptrp
	Reflect     = zap.Reflect
	Namespace   = zap.Namespace
	Stringer    = zap.Stringer
	Time        = zap.Time
	Timep       = zap.Timep
	Stack       = zap.Stack
	StackSkip   = zap.StackSkip
	Duration    = zap.Duration
	Durationp   = zap.Durationp
	Object      = zap.Object
	Any         = zap.Any
)
View Source
var (
	Debug  = std.Debug
	Info   = std.Info
	Warn   = std.Warn
	Error  = std.Error
	DPanic = std.DPanic
	Panic  = std.Panic
	Fatal  = std.Fatal
	Sync   = std.Sync
)

使用method value语法将std实例的各个方法以包级函数的形式暴露给用户,简化用户对logger实例的获取

Functions

func GetSizeLogWriter

func GetSizeLogWriter(filename string, maxsize, maxBackup, maxAge int, compress bool) zapcore.WriteSyncer

GetSizeLogWriter 负责日志写入的位置

func ResetDefault

func ResetDefault(l *Logger)

ResetDefault not safe for concurrent use

Types

type Field

type Field = zap.Field

type Level

type Level = zapcore.Level
const (
	DebugLevel  Level = zap.DebugLevel  // -1
	InfoLevel   Level = zap.InfoLevel   // 0, default level
	WarnLevel   Level = zap.WarnLevel   // 1
	ErrorLevel  Level = zap.ErrorLevel  // 2
	DPanicLevel Level = zap.DPanicLevel // 3, used in development log
	// PanicLevel logs a message, then panics
	PanicLevel Level = zap.PanicLevel // 4
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel Level = zap.FatalLevel // 5
)

用户只需依赖我们封装后的log包,而无需显式依赖 zap/zapcore

type LevelEnablerFunc

type LevelEnablerFunc func(lvl Level) bool

type Logger

type Logger struct {
	L *zap.Logger
	// contains filtered or unexported fields
}

func New

func New(writer io.Writer, level Level, opts ...Option) *Logger

New create a new logger (not support log rotating).

func NewDefaultLogger

func NewDefaultLogger() *Logger

func NewTee

func NewTee(tops []TeeOption, opts ...Option) *Logger

NewTee 创建写多个log文件的logger。根据不同的日志级别,写入不同的文件

func NewWithSizeRotate

func NewWithSizeRotate(lCfg SizeRotateLogConfig, opts ...Option) *Logger

NewWithSizeRotate create a new logger support log rotating.

func (*Logger) DPanic

func (l *Logger) DPanic(msg string, fields ...Field)

func (*Logger) DPanicf

func (l *Logger) DPanicf(msg string, args ...interface{})

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields ...Field)

func (*Logger) Debugf

func (l *Logger) Debugf(msg string, args ...interface{})

func (*Logger) Error

func (l *Logger) Error(msg string, fields ...Field)

func (*Logger) Errorf

func (l *Logger) Errorf(msg string, args ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, fields ...Field)

func (*Logger) Fatalf

func (l *Logger) Fatalf(msg string, args ...interface{})

func (*Logger) Info

func (l *Logger) Info(msg string, fields ...Field)

func (*Logger) Infof

func (l *Logger) Infof(msg string, args ...interface{})

func (*Logger) Name

func (l *Logger) Name(name string)

func (*Logger) Panic

func (l *Logger) Panic(msg string, fields ...Field)

func (*Logger) Panicf

func (l *Logger) Panicf(msg string, args ...interface{})

func (*Logger) Sync

func (l *Logger) Sync() error

Sync 调用内核的Sync方法,刷新所有缓冲的日志条目 应用程序应该注意在退出之前调用Sync

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields ...Field)

func (*Logger) Warnf

func (l *Logger) Warnf(msg string, args ...interface{})

type Option

type Option = zap.Option

type SizeRotateLogConfig

type SizeRotateLogConfig struct {
	Level      Level  `json:"level"`       // Level 最低日志等级
	FileName   string `json:"file_name"`   // FileName 日志文件位置
	MaxSize    int    `json:"max_size"`    // MaxSize 进行切割之前,日志文件的最大大小(MB为单位),默认为100MB
	MaxAge     int    `json:"max_age"`     // MaxAge 是根据文件名中编码的时间戳保留旧日志文件的最大天数。
	MaxBackups int    `json:"max_backups"` // MaxBackups 是要保留的旧日志文件的最大数量。默认是保留所有旧的日志文件(尽管 MaxAge 可能仍会导致它们被删除。)
	Compress   bool   `json:"compress"`    // Compress 是否压缩保存
}

SizeRotateLogConfig 日志大小分割

type TeeOption

type TeeOption struct {
	W   io.Writer
	Lef LevelEnablerFunc
}

Jump to

Keyboard shortcuts

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