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

@@ -2,7 +2,6 @@ package http
import (
"fmt"
"log"
"net/http"
"net/url"
"path"
@@ -10,10 +9,14 @@ import (
"github.com/debridmediamanager.com/zurg/internal/config"
"github.com/debridmediamanager.com/zurg/internal/torrent"
"github.com/debridmediamanager.com/zurg/pkg/logutil"
"github.com/hashicorp/golang-lru/v2/expirable"
)
func HandleDirectoryListing(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, c config.ConfigInterface, cache *expirable.LRU[string, string]) {
rlog := logutil.NewLogger()
log := rlog.Named("http")
requestPath := path.Clean(r.URL.Path)
if data, exists := cache.Get(requestPath); exists {
@@ -35,13 +38,13 @@ func HandleDirectoryListing(w http.ResponseWriter, r *http.Request, t *torrent.T
case len(filteredSegments) == 3:
output, err = handleSingleTorrent(requestPath, w, r, t)
default:
log.Println("Not Found (http)", r.Method, requestPath, len(filteredSegments))
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
}