log

package
v0.0.0-...-4dc2fe1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithTracer

func ContextWithTracer(ctx context.Context, tracer Tracer) context.Context

ContextWithTracer 添加tracer 到context

func Debug

func Debug(ctx context.Context, format string, a ...interface{})

func Default

func Default(appName string)

Default default logger

func Error

func Error(ctx context.Context, format string, a ...interface{})

func GinContextWithTracer

func GinContextWithTracer(ctx *gin.Context, tracer Tracer)

GinContextWithTracer 添加tracer 到context

func GinLogger

func GinLogger(appName string) gin.HandlerFunc

GinLogger gin Logger

func Info

func Info(ctx context.Context, format string, a ...interface{})

func InfoLevelEnabler

func InfoLevelEnabler() zap.LevelEnablerFunc

func Init

func Init(options ...Option)

Init 日志初始化

func NewTraceId

func NewTraceId() string

func Warn

func Warn(ctx context.Context, format string, a ...interface{})

func WarnLevelEnabler

func WarnLevelEnabler() zap.LevelEnablerFunc

Types

type Config

type Config struct {
	AppName     string
	SplitFormat string
	Path        string
}

type CustomerLogger

type CustomerLogger interface {
	Info(format string, a ...interface{})
	Debug(format string, a ...interface{})
	Warn(format string, a ...interface{})
	Error(format string, a ...interface{})
}

type Logger

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

type Option

type Option func(*Logger)

Option customer option

func AddCore

func AddCore(fileName string, levelEnable zapcore.LevelEnabler, logFileOption ...rotate.Option) Option

AddCore add core

func SetConfig

func SetConfig(c Config) Option

SetConfig option Set Config

func SetEncoder

func SetEncoder(enc zapcore.Encoder) Option

SetEncoder Set customer Encoder

func SetZapOptions

func SetZapOptions(options ...zap.Option) Option

SetZapOptions Set zap Logger

type Tracer

type Tracer interface {
	// Finish tracer结束操作
	Finish() (self Tracer)
	// TraceId 获取traceId
	TraceId() (traceId string)
	// RequestTime 请求时间
	RequestTime() time.Time
	// ResponseTime 响应时间
	ResponseTime() time.Time
	// ProcessTime 处理时间
	ProcessTime() time.Duration
}

Tracer 链路跟踪

func GetTracerFromContext

func GetTracerFromContext(ctx context.Context) (tracer Tracer, ok bool)

GetTracerFromContext 从context 获取tracer

func GetTracerFromGinContext

func GetTracerFromGinContext(ctx *gin.Context) (tracer Tracer, ok bool)

GetTracerFromGinContext 从gin context 获取tracer

func NewTracer

func NewTracer(traceId, appName string) (self Tracer)

NewTracer 创建新的tracer

func WithTracer

func WithTracer(tracer Tracer, appName string) (self Tracer)

WithTracer 继承上一个tracer的tracerId 填写本服务appName

Directories

Path Synopsis
Package encoder copy from zapcore.jsonEncoder
Package encoder copy from zapcore.jsonEncoder
bufferpool
Package bufferpool houses zap's shared internal buffer pool.
Package bufferpool houses zap's shared internal buffer pool.

Jump to

Keyboard shortcuts

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