cmd/stepd: Better error logging

This commit is contained in:
Sasha Koshka 2024-12-05 14:20:16 -05:00
parent ffb0eb894a
commit 0da05d465e

View File

@ -6,7 +6,6 @@ import "path"
import "io/fs"
import "strings"
import "net/http"
import "html/template"
import "path/filepath"
import "git.tebibyte.media/sashakoshka/step"
import "git.tebibyte.media/sashakoshka/goutil/container"
@ -26,7 +25,6 @@ func (this *handler) ServeHTTP (res http.ResponseWriter, req *http.Request) {
remoteAddr = fmt.Sprintf("%s --??-> %s", addr, req.RemoteAddr)
}
log.Println("(i)", req.Method, req.URL, "from", remoteAddr)
// TODO log all this stuff
filesystem := this.environment.GetFS()
// normalize path
@ -87,13 +85,7 @@ func (this *handler) serveFile (res http.ResponseWriter, req *http.Request, file
Data: req,
})
if err != nil {
if tmplErr, ok := err.(*template.Error); ok {
log.Printf (
"ERR document %s:%s: %s\n",
name, tmplErr.Line, tmplErr.Description)
} else {
log.Printf("ERR document %s: %v\n", name, err)
}
this.logErr(name, err)
}
}
@ -109,6 +101,10 @@ func (this *handler) serveError (res http.ResponseWriter, req *http.Request, sta
log.Printf("ERR %d %s: %v\n", status, http.StatusText(status), message)
}
func (this *handler) logErr (name string, err error) {
log.Printf("ERR %s: %v\n", name, err)
}
func statFile (filesystem fs.FS, name string) (fs.FileInfo, error) {
if filesystem, ok := filesystem.(fs.StatFS); ok {
return filesystem.Stat(name)