2017-05-17 14:58:28 +02:00
|
|
|
// Package that provides the functionality to start und initialize the logger
|
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
logger "github.com/Sirupsen/logrus"
|
2017-05-29 22:53:51 +02:00
|
|
|
httpLib "github.com/genofire/golang-lib/http"
|
2017-05-17 14:58:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Current logger with it's configuration
|
|
|
|
var Log *logger.Logger
|
|
|
|
|
|
|
|
// Function to initiate a new logger
|
|
|
|
func init() {
|
|
|
|
Log = logger.New()
|
|
|
|
// Enable fallback, if core logger
|
|
|
|
log.SetOutput(Log.Writer())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function to add the information of a http request to the log
|
|
|
|
func HTTP(r *http.Request) *logger.Entry {
|
|
|
|
return Log.WithFields(logger.Fields{
|
2017-05-29 22:53:51 +02:00
|
|
|
"remote": httpLib.GetRemoteIP(r),
|
2017-05-17 14:58:28 +02:00
|
|
|
"method": r.Method,
|
|
|
|
"url": r.URL.RequestURI(),
|
|
|
|
})
|
|
|
|
}
|