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