This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
2017-03-30 13:51:22 +02:00
|
|
|
package lib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
log "github.com/Sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
Log := log.New()
|
|
|
|
|
2017-03-30 14:01:01 +02:00
|
|
|
func DisableTimestamp(value bool) {
|
|
|
|
Log.SetFormatter(&log.TextFormatter{
|
|
|
|
DisableTimestamp: value,
|
|
|
|
})
|
|
|
|
}
|
2017-03-30 13:51:22 +02:00
|
|
|
// 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,
|
2017-03-30 14:01:01 +02:00
|
|
|
"path": r.URL.Path,
|
2017-03-30 13:51:22 +02:00
|
|
|
})
|
|
|
|
}
|