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/log.go

35 lines
690 B
Go

// Package log provides the
// functionality to start und initialize to logger
package log
import (
"log"
"net/http"
logger "github.com/Sirupsen/logrus"
)
var Log *logger.Logger
type Logger logger.Entry
// 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 {
ip := r.Header.Get("X-Forwarded-For")
if len(ip) <= 1 {
ip = r.RemoteAddr
}
return Log.WithFields(logger.Fields{
"remote": ip,
"method": r.Method,
"url": r.URL.RequestURI(),
})
}