zaplog

package
v0.0.0-...-fa62366 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const LevelKey = "level"

LevelKey is logger level key.

Variables

View Source
var (
	// DefaultCaller is a Valuer that returns the file and line.
	DefaultCaller = Caller(3)
)

Functions

func Any

func Any(key string, value interface{}) zap.Field

func Value

func Value(ctx context.Context, v interface{}) interface{}

Value return the function value.

Types

type Config

type Config struct {
	Level        string
	LogName      string
	Stdout       bool
	MaxSize      int  //MaxSize:在进行切割之前,日志文件的最大大小(以MB为单位)
	MaxBackups   int  //MaxBackups:保留旧文件的最大个数
	MaxAge       int  //MaxAges:保留旧文件的最大天数
	Compress     bool //Compress:是否压缩/归档旧文件
	FilterKeys   []string
	FilterValues []string
}

type Filter

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

Filter is a logger filter.

func NewFilter

func NewFilter(opts ...FilterOption) *Filter

NewFilter new a logger filter.

type FilterOption

type FilterOption func(*Filter)

FilterOption is filter option.

func FilterKey

func FilterKey(key ...string) FilterOption

FilterKey with filter key.

func FilterLevel

func FilterLevel(level Level) FilterOption

FilterLevel with filter level.

func FilterValue

func FilterValue(value ...string) FilterOption

FilterValue with filter value.

type Level

type Level int8

Level is a logger level.

const (
	// LevelDebug is logger debug level.
	LevelDebug Level = iota - 1
	// LevelInfo is logger info level.
	LevelInfo
	// LevelWarn is logger warn level.
	LevelWarn
	// LevelError is logger error level.
	LevelError
	LevelDPanic
	LevelPanic
	// LevelFatal is logger fatal level
	LevelFatal
)

func ParseLevel

func ParseLevel(s string) Level

ParseLevel parses a level string into a logger Level value.

func (Level) String

func (l Level) String() string

type Logger

type Logger interface {
	Debug(msg string, fields ...zap.Field)
	Info(msg string, fields ...zap.Field)
	Warn(msg string, fields ...zap.Field)
	Error(msg string, fields ...zap.Field)
	DPanic(msg string, fields ...zap.Field)
	Panic(msg string, fields ...zap.Field)
	Fatal(msg string, fields ...zap.Field)

	Debugc(ctx context.Context, msg string, fields ...zap.Field)
	Infoc(ctx context.Context, msg string, fields ...zap.Field)
	Warnc(ctx context.Context, msg string, fields ...zap.Field)
	Errorc(ctx context.Context, msg string, fields ...zap.Field)
	DPanicc(ctx context.Context, msg string, fields ...zap.Field)
	Panicc(ctx context.Context, msg string, fields ...zap.Field)
	Fatalc(ctx context.Context, msg string, fields ...zap.Field)
}

Logger is a logger interface.

var (
	// DefaultLogger is default logger.
	DefaultLogger Logger = New(Config{})
)

func New

func New(cfg Config) Logger

type Valuer

type Valuer func(ctx context.Context) interface{}

Valuer is returns a zaplog value.

func Caller

func Caller(depth int) Valuer

Caller returns returns a Valuer that returns a pkg/file:line description of the caller.

func SpanID

func SpanID() Valuer

SpanID returns a spanid valuer.

func Timestamp

func Timestamp(layout string) Valuer

Timestamp returns a timestamp Valuer with a custom time format.

func TraceID

func TraceID() Valuer

TraceID returns a traceid valuer.

Jump to

Keyboard shortcuts

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