From 1b378d118d0b7b8e47a880664bd0bed0c57fbe73 Mon Sep 17 00:00:00 2001 From: Arrim Date: Wed, 4 Mar 2020 10:29:46 +0300 Subject: [PATCH] Added support custom logger --- middleware/logger.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/middleware/logger.go b/middleware/logger.go index bb49678..ca3061c 100644 --- a/middleware/logger.go +++ b/middleware/logger.go @@ -6,6 +6,7 @@ import ( "time" "github.com/gin-gonic/gin" + "github.com/rs/zerolog" "github.com/rs/zerolog/log" ) @@ -14,20 +15,20 @@ type LoggerConfig struct { } func Logger() gin.HandlerFunc { - return LoggerWithConfig(LoggerConfig{}) + return LoggerWithConfig(LoggerConfig{}, log.Logger) } func LoggerWithWriter(out io.Writer, notlogged ...string) gin.HandlerFunc { return LoggerWithConfig(LoggerConfig{ SkipPaths: notlogged, - }) + }, log.Logger) } -func LoggerWithConfig(conf LoggerConfig) gin.HandlerFunc { - return newLoggerMiddleware(conf) +func LoggerWithConfig(conf LoggerConfig, logger zerolog.Logger) gin.HandlerFunc { + return newLoggerMiddleware(conf, logger) } -func newLoggerMiddleware(conf LoggerConfig) gin.HandlerFunc { +func newLoggerMiddleware(conf LoggerConfig, logger zerolog.Logger) gin.HandlerFunc { skip := computeSkip(conf) return func(c *gin.Context) { @@ -44,7 +45,7 @@ func newLoggerMiddleware(conf LoggerConfig) gin.HandlerFunc { return } - log.Info(). + logger.Info(). Str("StartTimestamp", fmt.Sprintf("%d", start.Unix())). Str("ClientIP", c.ClientIP()). Str("Method", c.Request.Method).