summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-09-12 03:10:47 +0800
committerKeuin <[email protected]>2022-09-12 03:12:10 +0800
commitdc044914ac17040c8d7c2398d1a0a80b915891b0 (patch)
tree372ac5e0f824230831c5c9328a8e8ce2b77a6dc1
parent32fbadfff7205f94a5089ec8ff2fc1cef30d325d (diff)
Proper use of loggers.
-rw-r--r--bilibili/request.go6
-rw-r--r--recording/runner.go6
2 files changed, 5 insertions, 7 deletions
diff --git a/bilibili/request.go b/bilibili/request.go
index b740f6b..feb2b8f 100644
--- a/bilibili/request.go
+++ b/bilibili/request.go
@@ -4,7 +4,6 @@ import (
"encoding/json"
"github.com/keuin/slbr/common"
"io"
- "log"
"net"
"net/http"
"strings"
@@ -32,16 +31,15 @@ func (b Bilibili) newGet(url string) (req *http.Request, err error) {
// callGet make a GET request and parse response as a JSON document with given model.
func callGet[T BaseResponse[V], V any](b Bilibili, url string) (resp T, err error) {
- logger := log.Default()
req, err := b.newGet(url)
if err != nil {
- logger.Printf("ERROR: Cannot create HTTP request instance on API %v: %v", url, err)
+ b.logger.Error("Cannot create HTTP request instance on API %v: %v", url, err)
return
}
r, err := b.Do(req)
if err != nil {
- logger.Printf("ERROR: HTTP Request failed on API %v: %v", url, err)
+ b.logger.Error("HTTP Request failed on API %v: %v", url, err)
return
}
defer func() { _ = r.Body.Close() }()
diff --git a/recording/runner.go b/recording/runner.go
index fddb562..c44a06c 100644
--- a/recording/runner.go
+++ b/recording/runner.go
@@ -122,7 +122,7 @@ func tryRunTask(t *RunningTask) error {
}
if err2 != nil {
// some other unrecoverable error
- t.logger.Error("Cannot recover from error: %v")
+ t.logger.Error("Cannot recover from error: %v", err2)
return err2
}
}
@@ -297,10 +297,10 @@ func watcherRecoverableLoop(
chWatcherDown <- struct{}{}
return
case ErrTransport:
- task.logger.Error("ERROR: Watcher stopped due to an I/O error: %v", err)
+ task.logger.Error("Watcher stopped due to an I/O error: %v", err)
waitSeconds := task.Transport.RetryIntervalSeconds
task.logger.Warning(
- "WARNING: Sleep for %v second(s) before restarting watcher.\n",
+ "Sleep for %v second(s) before restarting watcher.\n",
waitSeconds,
)
time.Sleep(time.Duration(waitSeconds) * time.Second)