Documentation
¶
Index ¶
- Constants
- func AddCorrelationIDToLogger(c *gin.Context, l *zap.SugaredLogger) *zap.SugaredLogger
- func AddLoggerMiddleware(l *zap.SugaredLogger) gin.HandlerFunc
- func GetLoggerFromContext(c *gin.Context) (*zap.SugaredLogger, error)
- func LogRequest(fallBackLogger *zap.Logger) gin.HandlerFunc
- func New(lc LoggingConfig) *zap.SugaredLogger
- type LoggingConfig
Constants ¶
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 ¶
func New(lc LoggingConfig) *zap.SugaredLogger
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.