summaryrefslogtreecommitdiff
path: root/src/wikiarticle.go
diff options
context:
space:
mode:
authordev2026-06-26 14:14:52 +0200
committerdev2026-06-26 14:14:52 +0200
commit06536f57b1fdc76212da6b85fbc9287cc4f0de70 (patch)
tree755e49a396091f953c428cb59a4cf56f03463267 /src/wikiarticle.go
parent13992fedaa0beaf93f6214993c95e685d249638f (diff)
downloadhnimdbbot-06536f57b1fdc76212da6b85fbc9287cc4f0de70.tar.gz
feat: add three-level logging with per-request debug output
- New --log-level flag: debug (default info), info, silent debug: every API request logged (method, URL, status, duration) info: normal events (batch progress, entry counts, summaries) silent: only warnings and fatal errors - Replaced all log.Printf/Fatalf calls with level-gated helpers - API request timing added to queryWikiArticle, queryWikidataBatch, downloadFile - Retries and backoff logged in debug mode
Diffstat (limited to 'src/wikiarticle.go')
-rw-r--r--src/wikiarticle.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/wikiarticle.go b/src/wikiarticle.go
index c1ce486..5f7aaa1 100644
--- a/src/wikiarticle.go
+++ b/src/wikiarticle.go
@@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
- "log"
"net/http"
"net/url"
"strconv"
@@ -39,10 +38,11 @@ func (a *App) queryWikiArticle(name string) (wikiArticleEntry, int, error) {
var resp *http.Response
var err error
+ start := time.Now()
for attempt := 0; attempt < 5; attempt++ {
if attempt > 0 {
backoff := 1 << attempt
- log.Printf("retry %d/%d for %s after %ds backoff", attempt, 4, name, backoff)
+ logHTTPRetry(attempt, 4, backoff, name)
time.Sleep(time.Duration(backoff) * time.Second)
}
@@ -59,15 +59,18 @@ func (a *App) queryWikiArticle(name string) (wikiArticleEntry, int, error) {
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(io.LimitReader(resp.Body, 2048))
resp.Body.Close()
+ logHTTPRequest("GET", reqURL, resp.StatusCode, time.Since(start).Seconds())
return wikiArticleEntry{}, resp.StatusCode, fmt.Errorf("HTTP %d: %s", resp.StatusCode, body)
}
break
}
if err != nil {
+ logHTTPRequest("GET", reqURL, 0, time.Since(start).Seconds())
return wikiArticleEntry{}, 0, fmt.Errorf("http get: %w", err)
}
defer resp.Body.Close()
+ logHTTPRequest("GET", reqURL, resp.StatusCode, time.Since(start).Seconds())
var articles []map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&articles); err != nil {