Update log.go
This commit is contained in:
parent
5fec294f81
commit
a1bfeb4b14
14
lib/log.go
14
lib/log.go
|
@ -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,
|
||||
|
|
Reference in New Issue