genofire/hs_monolith
genofire
/
hs_monolith
Archived
1
0
Fork 0
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.
hs_monolith/lib/log/main.go

32 lines
531 B
Go
Raw Normal View History

package log
2017-03-30 14:49:14 +02:00
import (
"log"
"net/http"
logger "github.com/Sirupsen/logrus"
)
var Log *logger.Logger
type Logger logger.Entry
2017-03-30 17:02:20 +02:00
func init() {
2017-03-30 14:49:14 +02:00
Log = logger.New()
// Enable fallback if core logger is used:
2017-03-30 14:49:14 +02:00
log.SetOutput(Log.Writer())
}
// HTTP to add information of a httprequest to log
func HTTP(r *http.Request) *logger.Entry {
2017-03-30 14:49:14 +02:00
ip := r.Header.Get("X-Forwarded-For")
if len(ip) <= 1 {
ip = r.RemoteAddr
}
return Log.WithFields(logger.Fields{
2017-03-30 17:02:20 +02:00
"remote": ip,
2017-03-30 14:49:14 +02:00
"method": r.Method,
2017-03-30 17:02:20 +02:00
"url": r.URL.RequestURI(),
2017-03-30 14:49:14 +02:00
})
}