1
0
mirror of https://git.sr.ht/~yotam/shavit synced 2024-11-23 04:52:11 +01:00

Add logging for requests

This commit is contained in:
Yotam Nachum 2019-11-01 13:40:08 +02:00
parent 89276ae650
commit 3fbc877dda
2 changed files with 23 additions and 1 deletions

20
logger.go Normal file

@ -0,0 +1,20 @@
package main
import (
"log"
"git.sr.ht/~yotam/go-gemini"
)
type LoggingHandler struct {
handler gemini.Handler
}
func (h LoggingHandler) Handle(req gemini.Request) gemini.Response {
log.Println("Received request for", req.URL)
res := h.handler.Handle(req)
log.Println("Responsed for", req.URL, "with ", res.Status, res.Meta)
return res
}

@ -18,7 +18,9 @@ func main() {
log.Fatal(err)
}
err = gemini.ListenAndServe("", cfg.TLSCert, cfg.TLSKey, MainHandler{absSourceDir})
handler := LoggingHandler{MainHandler{absSourceDir}}
err = gemini.ListenAndServe("", cfg.TLSCert, cfg.TLSKey, handler)
if err != nil {
log.Fatal(err)
}