xzap

package
v0.0.0-...-1369677 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: Apache-2.0 Imports: 24 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 (
	// GatewaySystemField 日志系统域
	GatewaySystemField = zap.String("system", "gateway")

	// GrpcSystemField 日志系统域
	GrpcSystemField = zap.String("system", "grpc")

	// ServerField 服务端日志
	ServerField = zap.String("span.kind", "server")

	// ClientField 客户端日志
	ClientField = zap.String("span.kind", "client")

	// JsonPbMarshaller 序列化protobuf消息
	JsonPbMarshaller xlogging.JsonPbMarshaler = &jsonpb.Marshaler{}
)
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 DefaultMessageProducer

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

DefaultMessageProducer 写日志

func DefaultRecoveryHandlerFunc

func DefaultRecoveryHandlerFunc(ctx context.Context, p interface{}) (err error)

DefaultRecoveryHandlerFunc 恐慌默认处理

func DurationToTimeMillisField

func DurationToTimeMillisField(duration time.Duration) zapcore.Field

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

func GinZapLogger

func GinZapLogger(zapLogger *ZapLogger, msg string) gin.HandlerFunc

func PayloadStreamClientInterceptor

func PayloadStreamClientInterceptor(zapLogger *ZapLogger) grpc.StreamClientInterceptor

PayloadStreamClientInterceptor 流拦截器,用于记录客户端请求和响应

func PayloadStreamServerInterceptor

func PayloadStreamServerInterceptor(zapLogger *ZapLogger) grpc.StreamServerInterceptor

PayloadStreamServerInterceptor 流拦截器,用于记录服务端请求和响应

func PayloadUnaryClientInterceptor

func PayloadUnaryClientInterceptor(zapLogger *ZapLogger) grpc.UnaryClientInterceptor

PayloadUnaryClientInterceptor 一元拦截器,用于记录客户端端请求和响应

func PayloadUnaryServerInterceptor

func PayloadUnaryServerInterceptor(zapLogger *ZapLogger) grpc.UnaryServerInterceptor

PayloadUnaryServerInterceptor 一元服务器拦截器,用于记录服务端请求和响应

func TimeEncoder

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

TimeEncoder 设置时间格式化方式

Types

type BodyLogWriter

type BodyLogWriter struct {
	gin.ResponseWriter
	// contains filtered or unexported fields
}

func (BodyLogWriter) Write

func (w BodyLogWriter) Write(b []byte) (int, error)

func (BodyLogWriter) WriteString

func (w BodyLogWriter) WriteString(s string) (int, error)

type CodeToLevel

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

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

type CtxLogger

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

CtxLogger 日志上下文记录器

func NewContextLogger

func NewContextLogger(ctx context.Context) *CtxLogger

NewContextLogger 获取当前上下文日志记录器

func WithContext

func WithContext(ctx context.Context) *CtxLogger

WithContext 获取当前上下文日志记录器

func (*CtxLogger) Debug

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

Debug 调用 zap.Logger Debug

func (*CtxLogger) Debugf

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

Debugf 调用 zap.Logger Debug

func (*CtxLogger) Error

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

Error 调用 zap.Logger Error

func (*CtxLogger) Errorf

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

Errorf 调用 zap.Logger Error

func (*CtxLogger) Info

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

Info 调用 zap.Logger Info

func (*CtxLogger) Infof

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

Infof 调用 zap.Logger Info

func (*CtxLogger) Panic

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

Panic 调用 zap.Logger Panic

func (*CtxLogger) Panicf

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

Panicf 调用 zap.Logger Panic

func (*CtxLogger) Warn

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

Warn 调用 zap.Logger Warn

func (*CtxLogger) Warnf

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

Warnf 调用 zap.Logger Warn

type DurationToField

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

DurationToField 生成日志持续时间

type LogConf

type LogConf struct {
	ServiceName string
	Mode        string
	Path        string
	Level       string
	Compress    bool
	KeepDays    int
}

LogConf 配置信息

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 xlogging.ErrorToCode) Option

WithCodes 自定义error映射 error code.

func WithDecider

func WithDecider(f xlogging.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 RecoveryHandlerFuncContext

type RecoveryHandlerFuncContext func(ctx context.Context, p interface{}) (err error)

RecoveryHandlerFuncContext 将恐慌以error形式返回 上下文可以用于提取请求的元数据和上下文

type ZapLogger

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

ZapLogger zap日志

func SetUp

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

SetUp 初始化zap Logger

Jump to

Keyboard shortcuts

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