2017-05-06 14:37:24 +02:00
|
|
|
// Package log provides the
|
|
|
|
// functionality to start und initialize to logger
|
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
logger "github.com/Sirupsen/logrus"
|
2017-05-08 19:13:29 +02:00
|
|
|
|
|
|
|
httpLib "github.com/FreifunkBremen/freifunkmanager/lib/http"
|
2017-05-06 14:37:24 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// current logger with configuration
|
|
|
|
var Log *logger.Logger
|
|
|
|
|
|
|
|
// Function to initiate a new logger
|
|
|
|
func init() {
|
|
|
|
Log = logger.New()
|
|
|
|
log.SetOutput(Log.Writer()) // Enable fallback if core logger
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function to add the information of a http request to the log
|
|
|
|
// Input: pointer to the http request r
|
|
|
|
func HTTP(r *http.Request) *logger.Entry {
|
|
|
|
return Log.WithFields(logger.Fields{
|
2017-05-08 19:13:29 +02:00
|
|
|
"remote": httpLib.GetRemoteIP(r),
|
2017-05-06 14:37:24 +02:00
|
|
|
"method": r.Method,
|
|
|
|
"url": r.URL.RequestURI(),
|
|
|
|
})
|
|
|
|
}
|