Add proper logging

This commit is contained in:
Ben Sarmiento
2023-11-05 01:23:41 +01:00
parent 1b116c2194
commit a9c71a3e93
11 changed files with 103 additions and 96 deletions

View File

@@ -3,7 +3,6 @@ package dav
import (
"encoding/xml"
"fmt"
"log"
"net/http"
"path"
"strings"
@@ -11,10 +10,14 @@ import (
"github.com/debridmediamanager.com/zurg/internal/config"
"github.com/debridmediamanager.com/zurg/internal/torrent"
"github.com/debridmediamanager.com/zurg/pkg/dav"
"github.com/debridmediamanager.com/zurg/pkg/logutil"
"github.com/hashicorp/golang-lru/v2/expirable"
)
func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, c config.ConfigInterface, cache *expirable.LRU[string, string]) {
rlog := logutil.NewLogger()
log := rlog.Named("dav")
requestPath := path.Clean(r.URL.Path)
requestPath = strings.Trim(requestPath, "/")
@@ -38,13 +41,13 @@ func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.To
case len(filteredSegments) == 2:
output, err = handleSingleTorrent(requestPath, w, r, t)
default:
log.Println("Not Found", r.Method, requestPath)
log.Errorf("Request %s %s not found", r.Method, requestPath)
writeHTTPError(w, "Not Found", http.StatusNotFound)
return
}
if err != nil {
log.Printf("Error processing request: %v\n", err)
log.Errorf("Error processing request: %v", err)
writeHTTPError(w, "Server error", http.StatusInternalServerError)
return
}