From 04d253c1e65b75a7a00a510419cabce4bbdbfbf6 Mon Sep 17 00:00:00 2001 From: Seednode Date: Sat, 21 Jan 2023 16:37:32 -0600 Subject: [PATCH] Log accesses to /_/stats and reduce verbosity of GenerateCache() --- cmd/version.go | 2 +- cmd/web.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/version.go b/cmd/version.go index 8c39b44..1e704cd 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" ) -var Version = "0.33.2" +var Version = "0.33.3" func init() { rootCmd.AddCommand(versionCmd) diff --git a/cmd/web.go b/cmd/web.go index aff7c48..29d7cf3 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -86,7 +86,6 @@ func (i *Index) GenerateCache(args []string) { i.List = []string{} i.Mutex.Unlock() - fmt.Printf("%v | Preparing image cache...\n", time.Now().Format(LogDate)) getFileList(args, &Filters{}, "", i) } @@ -446,12 +445,23 @@ func serveStatsHandler(args []string, stats *ServeStats) http.HandlerFunc { w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") + startTime := time.Now() + response, err := stats.ListImages() if err != nil { log.Fatal(err) } - w.Write([]byte(response)) + w.Write(response) + + if Verbose { + fmt.Printf("%v | Served statistics page (%v) to %v in %v\n", + startTime.Format(LogDate), + humanReadableSize(len(response)), + getRealIp(r), + time.Since(startTime).Round(time.Microsecond), + ) + } } }