Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultClientCodeToLevel(code codes.Code) zapcore.Level
- func DefaultCodeToLevel(code codes.Code) zapcore.Level
- func DurationToTimeMillisField(duration time.Duration) zapcore.Field
- func GetZapLogger() *zap.Logger
- func TimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- func ToContext(ctx context.Context, logger *zap.Logger) context.Context
- type CodeToLevel
- type CtxLogger
- func (l *CtxLogger) Debug(msg string, fields ...zap.Field)
- func (l *CtxLogger) Debugf(format string, data ...interface{})
- func (l *CtxLogger) Error(msg string, fields ...zap.Field)
- func (l *CtxLogger) Errorf(format string, data ...interface{})
- func (l *CtxLogger) Extract() *zap.Logger
- func (l *CtxLogger) Info(msg string, fields ...zap.Field)
- func (l *CtxLogger) Infof(format string, data ...interface{})
- func (l *CtxLogger) Panic(msg string, fields ...zap.Field)
- func (l *CtxLogger) Panicf(format string, data ...interface{})
- func (l *CtxLogger) Warn(msg string, fields ...zap.Field)
- func (l *CtxLogger) Warnf(format string, data ...interface{})
- func (l *CtxLogger) WithField(fields ...zap.Field)
- type DurationToField
- type MessageProducer
- type Option
- type Options
- func (o *Options) CodeFunc(err error) codes.Code
- func (o *Options) DurationFunc(duration time.Duration) zapcore.Field
- func (o *Options) LevelFunc(code codes.Code) zapcore.Level
- func (o *Options) MessageFunc(ctx context.Context, msg string, level zapcore.Level, err error, ...)
- func (o *Options) ShouldLog(methodName string, err error) bool
- func (o *Options) TimestampFormat() string
- type ZapLogger
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 ¶
DefaultClientCodeToLevel 根据RPC客户端返回码返回zap日志级别
func DefaultCodeToLevel ¶
DefaultCodeToLevel 根据RPC服务端返回码返回zap日志级别
func DurationToTimeMillisField ¶
DurationToTimeMillisField 持续时间转换为毫秒并使用key[time_ms]
func GetZapLogger ¶
func TimeEncoder ¶
func TimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
TimeEncoder 设置时间格式化方式
Types ¶
type CodeToLevel ¶
CodeToLevel rpc返回码与zap日志级别映射
type CtxLogger ¶
type CtxLogger struct {
// contains filtered or unexported fields
}
func NewContextLogger ¶
func WithContext ¶
type DurationToField ¶
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 WithDurationField ¶
func WithDurationField(f DurationToField) Option
WithDurationField 自定义将请求持续时间映射到Zap字段
func WithMessageProducer ¶
func WithMessageProducer(f MessageProducer) Option
WithMessageProducer 自定义消息格式.
func WithTimestampFormat ¶
WithTimestampFormat 自定义日志字段中发出的时间戳
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
func NewDefaultClientOption ¶
func NewDefaultClientOption() *Options
func NewDefaultOption ¶
func NewDefaultOption() *Options
func (*Options) MessageFunc ¶
func (*Options) TimestampFormat ¶
Click to show internal directories.
Click to hide internal directories.