From dfcf1016a1a3b00d7b93d5341e3b7a22aadeed8e Mon Sep 17 00:00:00 2001 From: Geno Date: Thu, 30 Mar 2017 13:51:22 +0200 Subject: [PATCH] [TASK] add new logging --- lib/log.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lib/log.go diff --git a/lib/log.go b/lib/log.go new file mode 100644 index 0000000..8102921 --- /dev/null +++ b/lib/log.go @@ -0,0 +1,22 @@ +package lib + +import ( + "net/http" + + log "github.com/Sirupsen/logrus" +) + +Log := log.New() + +// LogHTTP to add information of a httprequest to log +func LogHTTP(r *http.Request) *log.Entry { + ip := r.Header.Get("X-Forwarded-For") + if len(ip) <= 1 { + ip = r.RemoteAddr + } + return Log.WithFields(log.Fields{ + "remote": ip, + "method": r.Method, + "path": r.URL.Path, + }) +}