Add logging functions to webserver

master
Nick Krichevsky 2019-03-10 15:35:12 -04:00
parent e05751d269
commit ea7de5e172
1 changed files with 13 additions and 0 deletions

View File

@ -39,3 +39,16 @@ func (server *Webserver) setupRoutes() {
})
router.Post("/paste", server.makePaste)
}
func (server *Webserver) log(level logrus.Level, req *http.Request, message interface{}) {
server.logExtra(level, req, message, nil)
}
func (server *Webserver) logExtra(level logrus.Level, req *http.Request, message interface{}, extra logrus.Fields) {
if extra == nil {
extra = make(logrus.Fields, 1)
}
extra["route"] = req.RequestURI
entry := server.logger.WithFields(extra)
entry.Log(level, message)
}