sum7/warehost
sum7
/
warehost
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.
warehost/lib/log/main.go

32 lines
556 B
Go
Raw Normal View History

2016-08-14 15:29:54 +02:00
package log
import (
"net/http"
log "github.com/Sirupsen/logrus"
"github.com/rifflock/lfshook"
)
var Log *log.Logger
func NewLogger(path string) *log.Logger {
if Log != nil {
return Log
}
Log = log.New()
//Log.Formatter = new(log.JSONFormatter)
Log.Hooks.Add(lfshook.NewHook(lfshook.PathMap{
log.WarnLevel: path,
log.ErrorLevel: path,
}))
return Log
}
func GetLog(r *http.Request, modul string, request string) *log.Entry {
return Log.WithFields(log.Fields{
"remote": r.RemoteAddr,
"modul": modul,
"request": request,
})
}