Add logging functions to webserver
parent
e05751d269
commit
ea7de5e172
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue