genofire/hs_monolith
genofire
/
hs_monolith
Archived
1
0
Fork 0

Update log.go

This commit is contained in:
Geno 2017-03-30 14:16:13 +02:00 committed by GitHub
parent 5fec294f81
commit a1bfeb4b14
1 changed files with 8 additions and 6 deletions

View File

@ -1,29 +1,31 @@
package lib
import (
"log"
"net/http"
log "github.com/Sirupsen/logrus"
logger "github.com/Sirupsen/logrus"
)
var Log *log.Logger
var Log *logger.Logger
func init(){
Log = log.New()
Log = logger.New()
log.SetOutput(logger.Writer())
}
func LogTimestamp(value bool) {
log.SetFormatter(&log.TextFormatter{
logger.SetFormatter(&logger.TextFormatter{
DisableTimestamp: value,
})
}
// LogHTTP to add information of a httprequest to log
func LogHTTP(r *http.Request) *log.Entry {
func LogHTTP(r *http.Request) *logger.Entry {
ip := r.Header.Get("X-Forwarded-For")
if len(ip) <= 1 {
ip = r.RemoteAddr
}
return Log.WithFields(log.Fields{
return Log.WithFields(logger.Fields{
"remote": ip,
"method": r.Method,
"path": r.URL.Path,