bzap

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

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

Go to latest
Published: Sep 25, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// InfoLevel logs everything
	InfoLevel = iota
	// ErrorLevel includes errors, slows, stacks
	ErrorLevel
	// SevereLevel only log severe messages
	SevereLevel
)

Variables

View Source
var (
	// ErrLogPathNotSet is an error that indicates the log path is not set.
	ErrLogPathNotSet = errors.New("log path must be set")
	// ErrLogServiceNameNotSet is an error that indicates that the service name is not set.
	ErrLogServiceNameNotSet = errors.New("log service name must be set")
)
View Source
var DefaultDurationToField = DurationToTimeMillisField

DefaultDurationToField 请求持续时间转换为Zap字段

Functions

func DefaultClientCodeToLevel

func DefaultClientCodeToLevel(code codes.Code) zapcore.Level

DefaultClientCodeToLevel 根据RPC客户端返回码返回zap日志级别

func DefaultCodeToLevel

func DefaultCodeToLevel(code codes.Code) zapcore.Level

DefaultCodeToLevel 根据RPC服务端返回码返回zap日志级别

func DurationToTimeMillisField

func DurationToTimeMillisField(duration time.Duration) zapcore.Field

DurationToTimeMillisField 持续时间转换为毫秒并使用key[time_ms]

func GetZapLogger

func GetZapLogger() *zap.Logger

func TimeEncoder

func TimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

TimeEncoder 设置时间格式化方式

func ToContext

func ToContext(ctx context.Context, logger *zap.Logger) context.Context

Types

type CodeToLevel

type CodeToLevel func(code codes.Code) zapcore.Level

CodeToLevel rpc返回码与zap日志级别映射

type CtxLogger

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

func NewContextLogger

func NewContextLogger(ctx context.Context) *CtxLogger

func WithContext

func WithContext(ctx context.Context) *CtxLogger

func (*CtxLogger) Debug

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

func (*CtxLogger) Debugf

func (l *CtxLogger) Debugf(format string, data ...interface{})

func (*CtxLogger) Error

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

func (*CtxLogger) Errorf

func (l *CtxLogger) Errorf(format string, data ...interface{})

func (*CtxLogger) Extract

func (l *CtxLogger) Extract() *zap.Logger

func (*CtxLogger) Info

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

func (*CtxLogger) Infof

func (l *CtxLogger) Infof(format string, data ...interface{})

func (*CtxLogger) Panic

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

func (*CtxLogger) Panicf

func (l *CtxLogger) Panicf(format string, data ...interface{})

func (*CtxLogger) Warn

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

func (*CtxLogger) Warnf

func (l *CtxLogger) Warnf(format string, data ...interface{})

func (*CtxLogger) WithField

func (l *CtxLogger) WithField(fields ...zap.Field)

type DurationToField

type DurationToField func(duration time.Duration) zapcore.Field

DurationToField 生成日志持续时间

type MessageProducer

type MessageProducer func(ctx context.Context, msg string, level zapcore.Level, err error, fields []zapcore.Field)

MessageProducer 生成日志消息

type Option

type Option func(*Options)

Option 可选参数

func WithCodes

func WithCodes(f blog.ErrorToCode) Option

WithCodes 自定义error映射 error code.

func WithDecider

func WithDecider(f blog.Decider) Option

WithDecider 自定义拦截器日志是否记录

func WithDurationField

func WithDurationField(f DurationToField) Option

WithDurationField 自定义将请求持续时间映射到Zap字段

func WithLevels

func WithLevels(f CodeToLevel) Option

WithLevels 定义gRPC返回码和拦截器日志级别映射

func WithMessageProducer

func WithMessageProducer(f MessageProducer) Option

WithMessageProducer 自定义消息格式.

func WithTimestampFormat

func WithTimestampFormat(format string) Option

WithTimestampFormat 自定义日志字段中发出的时间戳

type Options

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

func NewDefaultClientOption

func NewDefaultClientOption() *Options

func NewDefaultOption

func NewDefaultOption() *Options

func (*Options) CodeFunc

func (o *Options) CodeFunc(err error) codes.Code

func (*Options) DurationFunc

func (o *Options) DurationFunc(duration time.Duration) zapcore.Field

func (*Options) LevelFunc

func (o *Options) LevelFunc(code codes.Code) zapcore.Level

func (*Options) MessageFunc

func (o *Options) MessageFunc(ctx context.Context, msg string, level zapcore.Level, err error, fields []zapcore.Field)

func (*Options) ShouldLog

func (o *Options) ShouldLog(methodName string, err error) bool

func (*Options) TimestampFormat

func (o *Options) TimestampFormat() string

type ZapLogger

type ZapLogger struct {
	Logger *zap.Logger
	Opts   []Option
}

ZapLogger zap日志

func SetUp

func SetUp(c blog.LogConf) (*ZapLogger, error)

SetUp 初始化zap Logger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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