xzap

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultLoggerName = "default"
)

Variables

View Source
var (

	// Get retrieves a buffer from the pool, creating one if necessary.
	Get = _pool1.Get
)

Functions

func NewConsoleEncoder

func NewConsoleEncoder(opt *Option, cfg zapcore.EncoderConfig) zapcore.Encoder

NewConsoleEncoder creates an encoder whose output is designed for human - rather than machine - consumption. It serializes the core log entry data (message, level, timestamp, etc.) in a plain-text format and leaves the structured context as JSON.

Note that although the console encoder doesn't use the keys specified in the encoder configuration, it will omit any element whose key is set to the empty string.

func NewJSONEncoder

func NewJSONEncoder(opt *Option, cfg zapcore.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 NewTextEncoder

func NewTextEncoder(opt *Option, cfg zapcore.EncoderConfig) zapcore.Encoder

NewTextEncoder creates a fast, low-allocation Text 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 Text 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.

Types

type MapObjectEncoder

type MapObjectEncoder struct {
	// Fields contains the entire encoded log context.
	Fields map[string]interface{}
	// contains filtered or unexported fields
}

MapObjectEncoder is an ObjectEncoder backed by a simple map[string]interface{}. It's not fast enough for production use, but it's helpful in tests.

func NewMapObjectEncoder

func NewMapObjectEncoder() *MapObjectEncoder

NewMapObjectEncoder creates a new map-backed ObjectEncoder.

func (*MapObjectEncoder) AddArray

func (m *MapObjectEncoder) AddArray(key string, v zapcore.ArrayMarshaler) error

AddArray implements ObjectEncoder.

func (*MapObjectEncoder) AddBinary

func (m *MapObjectEncoder) AddBinary(k string, v []byte)

AddBinary implements ObjectEncoder.

func (*MapObjectEncoder) AddBool

func (m *MapObjectEncoder) AddBool(k string, v bool)

AddBool implements ObjectEncoder.

func (*MapObjectEncoder) AddByteString

func (m *MapObjectEncoder) AddByteString(k string, v []byte)

AddByteString implements ObjectEncoder.

func (*MapObjectEncoder) AddComplex128

func (m *MapObjectEncoder) AddComplex128(k string, v complex128)

AddComplex128 implements ObjectEncoder.

func (*MapObjectEncoder) AddComplex64

func (m *MapObjectEncoder) AddComplex64(k string, v complex64)

AddComplex64 implements ObjectEncoder.

func (MapObjectEncoder) AddDuration

func (m MapObjectEncoder) AddDuration(k string, v time.Duration)

AddDuration implements ObjectEncoder.

func (*MapObjectEncoder) AddFloat32

func (m *MapObjectEncoder) AddFloat32(k string, v float32)

AddFloat32 implements ObjectEncoder.

func (*MapObjectEncoder) AddFloat64

func (m *MapObjectEncoder) AddFloat64(k string, v float64)

AddFloat64 implements ObjectEncoder.

func (*MapObjectEncoder) AddInt

func (m *MapObjectEncoder) AddInt(k string, v int)

AddInt implements ObjectEncoder.

func (*MapObjectEncoder) AddInt16

func (m *MapObjectEncoder) AddInt16(k string, v int16)

AddInt16 implements ObjectEncoder.

func (*MapObjectEncoder) AddInt32

func (m *MapObjectEncoder) AddInt32(k string, v int32)

AddInt32 implements ObjectEncoder.

func (*MapObjectEncoder) AddInt64

func (m *MapObjectEncoder) AddInt64(k string, v int64)

AddInt64 implements ObjectEncoder.

func (*MapObjectEncoder) AddInt8

func (m *MapObjectEncoder) AddInt8(k string, v int8)

AddInt8 implements ObjectEncoder.

func (*MapObjectEncoder) AddObject

AddObject implements ObjectEncoder.

func (*MapObjectEncoder) AddReflected

func (m *MapObjectEncoder) AddReflected(k string, v interface{}) error

AddReflected implements ObjectEncoder.

func (*MapObjectEncoder) AddString

func (m *MapObjectEncoder) AddString(k string, v string)

AddString implements ObjectEncoder.

func (MapObjectEncoder) AddTime

func (m MapObjectEncoder) AddTime(k string, v time.Time)

AddTime implements ObjectEncoder.

func (*MapObjectEncoder) AddUint

func (m *MapObjectEncoder) AddUint(k string, v uint)

AddUint implements ObjectEncoder.

func (*MapObjectEncoder) AddUint16

func (m *MapObjectEncoder) AddUint16(k string, v uint16)

AddUint16 implements ObjectEncoder.

func (*MapObjectEncoder) AddUint32

func (m *MapObjectEncoder) AddUint32(k string, v uint32)

AddUint32 implements ObjectEncoder.

func (*MapObjectEncoder) AddUint64

func (m *MapObjectEncoder) AddUint64(k string, v uint64)

AddUint64 implements ObjectEncoder.

func (*MapObjectEncoder) AddUint8

func (m *MapObjectEncoder) AddUint8(k string, v uint8)

AddUint8 implements ObjectEncoder.

func (*MapObjectEncoder) AddUintptr

func (m *MapObjectEncoder) AddUintptr(k string, v uintptr)

AddUintptr implements ObjectEncoder.

func (*MapObjectEncoder) OpenNamespace

func (m *MapObjectEncoder) OpenNamespace(k string)

OpenNamespace implements ObjectEncoder.

type Option

type Option struct {
	Name           string // 代表logger
	NoFile         bool   // 是否为开发模式,如果是true,只显示到标准输出,同旧的 NoFile
	Format         string
	WritableStack  bool // 是否需要打印error及以上级别的堆栈信息
	Skip           int
	WritableCaller bool // 是否需要打印行号函数信息
	Level          string
	Path           string
	FileName       string
	PackageLevel   map[string]string // 包级别日志等级设置
	ErrlogLevel    string            // 错误日志级别,默认error
	ErrorPath      string
	MaxAge         int  // 保留旧文件的最大天数,默认7天
	MaxBackups     int  // 保留旧文件的最大个数,默认7个
	MaxSize        int  // 在进行切割之前,日志文件的最大大小(以MB为单位)默认1024
	Compress       bool // 是否压缩/归档旧文件
	// contains filtered or unexported fields
}

Option 是日志配置选项

func DefaultOption

func DefaultOption() *Option

type XZap

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

func Default

func Default() *XZap

func New

func New(opt *Option) (*XZap, error)

func (*XZap) DPanicf

func (xZap *XZap) DPanicf(format string, params ...interface{})

func (*XZap) Debugf

func (xZap *XZap) Debugf(format string, fields ...interface{})

func (*XZap) Errorf

func (xZap *XZap) Errorf(format string, fields ...interface{})

func (*XZap) Fatalf

func (xZap *XZap) Fatalf(format string, fields ...interface{})

func (*XZap) Infof

func (xZap *XZap) Infof(format string, fields ...interface{})

func (*XZap) Level

func (xZap *XZap) Level() xlog.Level

func (*XZap) Panicf

func (xZap *XZap) Panicf(format string, fields ...interface{})

func (*XZap) Warnf

func (xZap *XZap) Warnf(format string, fields ...interface{})

Jump to

Keyboard shortcuts

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