genofire/hs_monolith
genofire
/
hs_monolith
Archived
1
0
Fork 0

[TASK] add new logging

This commit is contained in:
Geno 2017-03-30 13:51:22 +02:00 committed by GitHub
parent 0a81ae70d4
commit dfcf1016a1
1 changed files with 22 additions and 0 deletions

22
lib/log.go Normal file
View File

@ -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,
})
}