From 4b2c7d212aa1894b79ebea9be87739716e4112fd Mon Sep 17 00:00:00 2001 From: Simon Sawert Date: Mon, 1 Jul 2019 09:52:19 +0200 Subject: [PATCH] Use interface to create logger By using the FieldLogger interface the logger supports both new logrus loggers and existing field loggers such as an entry. This is useful if the enduser uses an existing logrus logger with existing fields. --- logger.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/logger.go b/logger.go index d97d4b7..57c817d 100644 --- a/logger.go +++ b/logger.go @@ -19,7 +19,7 @@ import ( var timeFormat = "02/Jan/2006:15:04:05 -0700" // Logger is the logrus logger handler -func Logger(log *logrus.Logger) gin.HandlerFunc { +func Logger(logger logrus.FieldLogger) gin.HandlerFunc { hostname, err := os.Hostname() if err != nil { hostname = "unknow" @@ -40,7 +40,7 @@ func Logger(log *logrus.Logger) gin.HandlerFunc { dataLength = 0 } - entry := logrus.NewEntry(log).WithFields(logrus.Fields{ + entry := logger.WithFields(logrus.Fields{ "hostname": hostname, "statusCode": statusCode, "latency": latency, // time to process