logging

package
v0.0.0-...-e48215e Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2022 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LoggerKey = "logger"

	CorrelationIDName         ctxKey = "correlation_id"
	IntCorrelationIDName      ctxKey = "int_correlation_id"
	ExternalCorrelationIDName string = "X-Correlation-Id"
)

Variables

This section is empty.

Functions

func AddCorrelationIDToLogger

func AddCorrelationIDToLogger(c *gin.Context, l *zap.SugaredLogger) *zap.SugaredLogger

AddCorrelationIDToLogger takes correlation ID from the request context and enriches the logger with them. The param logger cannot be nil.

func AddLoggerMiddleware

func AddLoggerMiddleware(l *zap.SugaredLogger) gin.HandlerFunc

AddLoggerMiddleware adds a logger to the gin context, with some fields populated (correlation ID, requests params, ...). The logger can be retrieved by calling GetLoggerFromContext(c).

func GetLoggerFromContext

func GetLoggerFromContext(c *gin.Context) (*zap.SugaredLogger, error)

func LogRequest

func LogRequest(fallBackLogger *zap.Logger) gin.HandlerFunc

LogRequest is a gin middleware that logs useful informations on each request as they come.

func New

New creates a zap.SugaredLogger configured following lc's directives. The non-debug logger returned by New is configured to output JSON-encoded structured logs to stdout. If lc.LogPath is empty, no log file is created, otherwise it will be compressed and rotated every 20MB, or when it reaches 28 days of usage. The last 3 copies are kept for backup.

Types

type LoggingConfig

type LoggingConfig struct {
	LogPath string
	JSON    bool
	Debug   bool
}

Jump to

Keyboard shortcuts

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