From 3b39db87757285017b0cb4f23de54714f350ddd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Wilczy=C5=84ski?= Date: Wed, 3 Jan 2024 18:00:04 +0100 Subject: [PATCH] [SRE-221] Reduce logs printend on the default verbosity level --- catalyst-uploader.go | 10 +++++----- core/uploader.go | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/catalyst-uploader.go b/catalyst-uploader.go index 6646d65..05b24ee 100644 --- a/catalyst-uploader.go +++ b/catalyst-uploader.go @@ -3,10 +3,10 @@ package main import ( "encoding/json" "flag" - "log" "os" "time" + "github.com/golang/glog" "github.com/livepeer/catalyst-uploader/core" "github.com/livepeer/go-tools/drivers" ) @@ -32,7 +32,7 @@ func run() int { } if flag.NArg() == 0 { - log.Fatal("Destination URI is not specified. See -h for usage.") + glog.Fatal("Destination URI is not specified. See -h for usage.") return 1 } @@ -42,20 +42,20 @@ func run() int { uri := flag.Arg(0) if uri == "" { - log.Fatalf("Could not parse object store URI: %s", uri) + glog.Fatalf("Could not parse object store URI: %s", uri) return 1 } err := core.Upload(os.Stdin, uri, WaitBetweenWrites, *timeout) if err != nil { - log.Fatalf("Uploader failed for %s: %s", uri, err) + glog.Fatalf("Uploader failed for %s: %s", uri, err) return 1 } // success, write uploaded file details to stdout err = json.NewEncoder(stdout).Encode(map[string]string{"uri": uri}) if err != nil { - log.Println(err) + glog.Println(err) return 1 } diff --git a/core/uploader.go b/core/uploader.go index 8ee5ec5..b835094 100644 --- a/core/uploader.go +++ b/core/uploader.go @@ -6,7 +6,6 @@ import ( "context" "fmt" "io" - "log" "os" "os/exec" "path/filepath" @@ -14,6 +13,7 @@ import ( "time" "github.com/cenkalti/backoff/v4" + "github.com/golang/glog" "github.com/livepeer/go-tools/drivers" ) @@ -62,7 +62,7 @@ func Upload(input io.Reader, outputURI string, waitBetweenWrites, writeTimeout t err = backoff.Retry(func() error { _, err := session.SaveData(context.Background(), "", bytes.NewReader(fileContents), fields, writeTimeout) if err != nil { - log.Printf("failed upload attempt: %s", err) + glog.Errorf("failed upload attempt: %v", err) } return err }, UploadRetryBackoff()) @@ -71,7 +71,7 @@ func Upload(input io.Reader, outputURI string, waitBetweenWrites, writeTimeout t } if err = extractThumb(session, outputURI, fileContents); err != nil { - log.Printf("extracting thumbnail failed: %s", err) + glog.Errorf("extracting thumbnail failed: %v", err) } return nil } @@ -99,16 +99,16 @@ func Upload(input io.Reader, outputURI string, waitBetweenWrites, writeTimeout t b := scanner.Bytes() fileContents = append(fileContents, b...) if strings.Contains(outputURI, "m3u8") { - log.Printf("Received new bytes for %s: %s", outputURI, string(b)) + glog.V(5).Infof("Received new bytes for %s: %s", outputURI, string(b)) } // Only write the latest version of the data that's been piped in if enough time has elapsed since the last write if lastWrite.Add(waitBetweenWrites).Before(time.Now()) { if _, err := session.SaveData(context.Background(), "", bytes.NewReader(fileContents), fields, writeTimeout); err != nil { // Just log this error, since it'll effectively be retried after the next interval - log.Printf("Failed to write: %s", err) + glog.Errorf("Failed to write: %v", err) } else { - log.Printf("Wrote %s to storage: %d bytes", outputURI, len(b)) + glog.V(5).Infof("Wrote %s to storage: %d bytes", outputURI, len(b)) } lastWrite = time.Now() } @@ -122,7 +122,7 @@ func Upload(input io.Reader, outputURI string, waitBetweenWrites, writeTimeout t // Don't ignore this error, since there won't be any further attempts to write return fmt.Errorf("failed to write final save: %w", err) } - + glog.Infof("Completed writing %s to storage", outputURI) return nil }