ginlogrus

package
v0.0.0-...-349f3ea Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttachTraceID

func AttachTraceID(ctx context.Context, traceID string) context.Context

AttachTraceID will attach a brand-new request ID to a http request

func GetTraceID

func GetTraceID(ctx context.Context) string

GetTraceID will get reqID from a http request and return it as a string.

func GetTraceIDGin

func GetTraceIDGin(c *gin.Context) string

GetTraceIDGin will get reqID from a http request and return it as a string.

func Logger

func Logger(l0 logrus.FieldLogger, filter bool) gin.HandlerFunc

Logger is the logrus logger handler Filter static when true

func NewLogger

func NewLogger(traceID string, ancestor logrus.FieldLogger) logrus.FieldLogger

NewLogger creates a *logrus.Entry that has requestID as a field. A new LogField inst will be created if log is nil

func NewLoggerCtx

func NewLoggerCtx(ctx context.Context, ancestor logrus.FieldLogger) logrus.FieldLogger

NewLoggerCtx creates a *logrus.Entry that has requestID as a field. A new LogField inst will be created if log is nil.

func NewLoggerGin

func NewLoggerGin(c *gin.Context, ancestor logrus.FieldLogger) logrus.FieldLogger

func TraceIDMiddleware

func TraceIDMiddleware(next http.Handler) http.Handler

TraceIDMiddleware will attach the traceID to the http.Request and add traceID to http header in the response.

Types

type ContextKey

type ContextKey string

ContextKey is context key type.

const (
	// ContextKeyTraceID is the context key for TraceID.
	ContextKeyTraceID ContextKey = "TRACE_ID"

	// HTTPHeaderNamTraceID has the name of the header for trace ID.
	HTTPHeaderNamTraceID = "X-TRACE-ID"
)

Jump to

Keyboard shortcuts

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