logz

package
v0.0.0-...-ac3b76c Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DebugLevel 打印Debug级别日志
	DebugLevel level = zap.DebugLevel
	// InfoLevel 打印Info级别日志
	InfoLevel level = zap.InfoLevel
	// WarnLevel 打印Warn级别日志
	WarnLevel level = zap.WarnLevel
	// ErrorLevel 打印Error级别日志和调用栈
	ErrorLevel level = zap.ErrorLevel
	// PanicLevel 打印Panic级别日志和调用栈并panic退出
	PanicLevel level = zap.PanicLevel
	// FatalLevel 打印Fatal级别日志和调用栈并调用os.Exit(1)退出
	FatalLevel level = zap.FatalLevel
)

Variables

View Source
var LevelM = map[level]string{
	DebugLevel: "DEBUG",
	InfoLevel:  "NOTICE",
	WarnLevel:  "WARN",
	ErrorLevel: "FATAL",
	PanicLevel: "FATAL",
	FatalLevel: "FATAL",
}

Functions

func Debug

func Debug(msg string, fields ...field)

Debug 使用defaultLogger实例打印Debug级别日志

func E

func E(err error) field

E 是F("error", err)的语法糖,用来构造错误err的filed,其key为"error"

func Error

func Error(msg string, fields ...field)

Error 使用defaultLogger实例打印Error级别日志。注:此级别下会打印调用栈,请根据需求使用

func F

func F(key string, value interface{}) field

F 返回一个指定key的field

func Fatal

func Fatal(msg string, fields ...field)

Fatal 使用defaultLogger实例打印Fatal级别日志。注:此级别下会打印调用栈,同时会调用os.Exit(1)退出,请根据需求使用

func FmtTime

func FmtTime() string

FmtTime 返回格式化时间

func Handler

func Handler() http.Handler

Handler 返回atom httpHandler

func Info

func Info(msg string, fields ...field)

Info 使用defaultLogger实例打印Info级别日志

func NewFileWriter

func NewFileWriter(path string) writer

NewFileWriter 返回写文件的writer

func NewJSONEncoder

func NewJSONEncoder(cfg EncoderConfig) zapcore.Encoder

NewJSONEncoder creates a fast, low-allocation JSON encoder. The encoder appropriately escapes all field keys and values.

Note that the encoder doesn't deduplicate keys, so it's possible to produce a message like

{"foo":"bar","foo":"baz"}

This is permitted by the JSON specification, but not encouraged. Many libraries will ignore duplicate key-value pairs (typically keeping the last pair) when unmarshaling, but users should attempt to avoid adding duplicate keys.

func NewStdErrWriter

func NewStdErrWriter() writer

NewStdErrWriter 返回写标准错误输出的writer

func Panic

func Panic(msg string, fields ...field)

Panic 使用defaultLogger实例打印Panic级别日志。注:此级别下会打印调用栈,同时会Panic,请根据需求使用

func SetDefaultLogger

func SetDefaultLogger(l *Logger)

SetDefaultLogger 根据输入的Options初始化默认logger实例

func SyncTime

func SyncTime()

SyncTime 同步时间

func Warn

func Warn(msg string, fields ...field)

Warn 使用defaultLogger实例打印Warn级别日志

Types

type EncoderConfig

type EncoderConfig struct {
	zapcore.EncoderConfig
	PrefixFns []PrefixFn
}

type JsonEncoder

type JsonEncoder struct {
	*zapcore.EncoderConfig

	Buf *buffer.Buffer
	// contains filtered or unexported fields
}

func (*JsonEncoder) AddArray

func (enc *JsonEncoder) AddArray(key string, arr zapcore.ArrayMarshaler) error

func (*JsonEncoder) AddBinary

func (enc *JsonEncoder) AddBinary(key string, val []byte)

func (*JsonEncoder) AddBool

func (enc *JsonEncoder) AddBool(key string, val bool)

func (*JsonEncoder) AddByteString

func (enc *JsonEncoder) AddByteString(key string, val []byte)

func (*JsonEncoder) AddComplex128

func (enc *JsonEncoder) AddComplex128(key string, val complex128)

func (*JsonEncoder) AddComplex64

func (enc *JsonEncoder) AddComplex64(k string, v complex64)

func (*JsonEncoder) AddDuration

func (enc *JsonEncoder) AddDuration(key string, val time.Duration)

func (*JsonEncoder) AddFloat32

func (enc *JsonEncoder) AddFloat32(k string, v float32)

func (*JsonEncoder) AddFloat64

func (enc *JsonEncoder) AddFloat64(key string, val float64)

func (*JsonEncoder) AddInt

func (enc *JsonEncoder) AddInt(k string, v int)

func (*JsonEncoder) AddInt16

func (enc *JsonEncoder) AddInt16(k string, v int16)

func (*JsonEncoder) AddInt32

func (enc *JsonEncoder) AddInt32(k string, v int32)

func (*JsonEncoder) AddInt64

func (enc *JsonEncoder) AddInt64(key string, val int64)

func (*JsonEncoder) AddInt8

func (enc *JsonEncoder) AddInt8(k string, v int8)

func (*JsonEncoder) AddObject

func (enc *JsonEncoder) AddObject(key string, obj zapcore.ObjectMarshaler) error

func (*JsonEncoder) AddReflected

func (enc *JsonEncoder) AddReflected(key string, obj interface{}) error

func (*JsonEncoder) AddString

func (enc *JsonEncoder) AddString(key, val string)

func (*JsonEncoder) AddTime

func (enc *JsonEncoder) AddTime(key string, val time.Time)

func (*JsonEncoder) AddUint

func (enc *JsonEncoder) AddUint(k string, v uint)

func (*JsonEncoder) AddUint16

func (enc *JsonEncoder) AddUint16(k string, v uint16)

func (*JsonEncoder) AddUint32

func (enc *JsonEncoder) AddUint32(k string, v uint32)

func (*JsonEncoder) AddUint64

func (enc *JsonEncoder) AddUint64(key string, val uint64)

func (*JsonEncoder) AddUint8

func (enc *JsonEncoder) AddUint8(k string, v uint8)

func (*JsonEncoder) AddUintptr

func (enc *JsonEncoder) AddUintptr(k string, v uintptr)

func (*JsonEncoder) AppendArray

func (enc *JsonEncoder) AppendArray(arr zapcore.ArrayMarshaler) error

func (*JsonEncoder) AppendBool

func (enc *JsonEncoder) AppendBool(val bool)

func (*JsonEncoder) AppendByteString

func (enc *JsonEncoder) AppendByteString(val []byte)

func (*JsonEncoder) AppendComplex128

func (enc *JsonEncoder) AppendComplex128(val complex128)

func (*JsonEncoder) AppendComplex64

func (enc *JsonEncoder) AppendComplex64(v complex64)

func (*JsonEncoder) AppendDuration

func (enc *JsonEncoder) AppendDuration(val time.Duration)

func (*JsonEncoder) AppendFloat32

func (enc *JsonEncoder) AppendFloat32(v float32)

func (*JsonEncoder) AppendFloat64

func (enc *JsonEncoder) AppendFloat64(v float64)

func (*JsonEncoder) AppendInt

func (enc *JsonEncoder) AppendInt(v int)

func (*JsonEncoder) AppendInt16

func (enc *JsonEncoder) AppendInt16(v int16)

func (*JsonEncoder) AppendInt32

func (enc *JsonEncoder) AppendInt32(v int32)

func (*JsonEncoder) AppendInt64

func (enc *JsonEncoder) AppendInt64(val int64)

func (*JsonEncoder) AppendInt8

func (enc *JsonEncoder) AppendInt8(v int8)

func (*JsonEncoder) AppendObject

func (enc *JsonEncoder) AppendObject(obj zapcore.ObjectMarshaler) error

func (*JsonEncoder) AppendReflected

func (enc *JsonEncoder) AppendReflected(val interface{}) error

func (*JsonEncoder) AppendString

func (enc *JsonEncoder) AppendString(val string)

func (*JsonEncoder) AppendTime

func (enc *JsonEncoder) AppendTime(val time.Time)

func (*JsonEncoder) AppendUint

func (enc *JsonEncoder) AppendUint(v uint)

func (*JsonEncoder) AppendUint16

func (enc *JsonEncoder) AppendUint16(v uint16)

func (*JsonEncoder) AppendUint32

func (enc *JsonEncoder) AppendUint32(v uint32)

func (*JsonEncoder) AppendUint64

func (enc *JsonEncoder) AppendUint64(val uint64)

func (*JsonEncoder) AppendUint8

func (enc *JsonEncoder) AppendUint8(v uint8)

func (*JsonEncoder) AppendUintptr

func (enc *JsonEncoder) AppendUintptr(v uintptr)

func (*JsonEncoder) Clone

func (enc *JsonEncoder) Clone() zapcore.Encoder

func (*JsonEncoder) EncodeEntry

func (enc *JsonEncoder) EncodeEntry(ent zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error)

func (*JsonEncoder) OpenNamespace

func (enc *JsonEncoder) OpenNamespace(key string)

type Logger

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

Logger 对zap.Logger进行了封装

func DefaultLogger

func DefaultLogger() *Logger

DefaultLogger 返回默认logger实例

func New

func New(ops ...Option) *Logger

New 构造logger实例

func (*Logger) Debug

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

Debug 打印Debug级别日志

func (*Logger) Error

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

Error 打印Error级别日志。注:此级别下会打印调用栈,请根据需求使用

func (*Logger) Fatal

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

Fatal 打印Fatal级别日志。注:此级别下会打印调用栈,同时会调用os.Exit(1)退出,请根据需求使用

func (*Logger) Handler

func (l *Logger) Handler() http.Handler

Handler 返回defaultLogger的atom httpHandler

func (*Logger) Info

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

Info 打印Info级别日志

func (*Logger) Panic

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

Panic 打印Panic级别日志。注:此级别下会打印调用栈,同时会Panic,请根据需求使用

func (*Logger) Warn

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

Warn 打印Warn级别日志

type Option

type Option interface {
	// contains filtered or unexported methods
}

An Option configures a Logger.

func Fields

func Fields(fields ...field) Option

Fields 为实例添加染色字段

func Level

func Level(lvl level) Option

Level 为实例设置默认日志级别

func LevelStr

func LevelStr(lvlStr string) Option

LevelStr 为实例设置默认日志级别,传入的参数是string

func Prefix

func Prefix(p ...string) Option

Prefix 设置输出前缀

func Writer

func Writer(w writer) Option

Writer 为实例设置默认writer

type PrefixFn

type PrefixFn func(encoder *JsonEncoder, ent zapcore.Entry)

Jump to

Keyboard shortcuts

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