From 61ed59cefaeaf96a302eab3ddc6b89266436f5d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Mon, 10 Oct 2022 14:55:22 +0200 Subject: [PATCH] Improve logging --- main.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index e0094de..b94524a 100644 --- a/main.go +++ b/main.go @@ -37,12 +37,12 @@ func (rcv *receiver) handleWebhooks(w http.ResponseWriter, r *http.Request) { if rcv.cfg.User != "" && rcv.cfg.Password != "" { user, pass, ok := r.BasicAuth() if !ok { - rcv.logger.Error("basic auth failure") + rcv.logger.Debug("basic auth failure") return } if user != rcv.cfg.User || pass != rcv.cfg.Password { - rcv.logger.Info("basic auth: wrong user or password") + rcv.logger.Debug("basic auth: wrong user or password") return } } @@ -50,19 +50,19 @@ func (rcv *receiver) handleWebhooks(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() if r.Method != http.MethodPost { - rcv.logger.Errorf("illegal HTTP method: expected %q, got %q", "POST", r.Method) + rcv.logger.Debugf("illegal HTTP method: expected %q, got %q", "POST", r.Method) return } contentType := r.Header.Get("Content-Type") if contentType != "application/json" { - rcv.logger.Errorf("illegal content type: %s", contentType) + rcv.logger.Debugf("illegal content type: %s", contentType) return } var event payload if err := json.NewDecoder(r.Body).Decode(&event); err != nil { - rcv.logger.Error(err) + rcv.logger.Debug(err) return } @@ -117,6 +117,7 @@ func (rcv *receiver) handleWebhooks(w http.ResponseWriter, r *http.Request) { defer resp.Body.Close() if resp.StatusCode != http.StatusOK { rcv.logger.Errorf("ntfy: received status code %d", resp.StatusCode) + return } } @@ -139,5 +140,6 @@ func main() { receiver := &receiver{cfg: cfg, logger: logger} http.HandleFunc("/", receiver.handleWebhooks) + logger.Infof("Listening on %s", cfg.HTTPAddress) logger.Fatal(http.ListenAndServe(cfg.HTTPAddress, nil)) }