Skip to content

Commit

Permalink
Start using structured logging for the little we do
Browse files Browse the repository at this point in the history
  • Loading branch information
fingon committed Oct 31, 2024
1 parent 5a76e13 commit 8043892
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cm/cm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright (c) 2024 Markus Stenberg
*
* Created: Fri Apr 26 10:44:18 2024 mstenber
* Last modified: Fri Apr 26 21:16:03 2024 mstenber
* Last modified: Thu Oct 31 08:02:09 2024 mstenber
* Edit time: 42 min
*
*/
Expand Down Expand Up @@ -112,7 +112,7 @@ func TestParse(t *testing.T) {
// Pretend we're new request: take in the cookie
sc4 := staticCookie{name: "cm-cm.tt", cookie: cookie, err: nil}
ts4 := tt{}
fmt.Printf("!!!\n")

changed, err = Parse(&sc4, &sc4.URLWrapper, &ts4)
assert.Equal(t, changed, false)
assert.Equal(t, err, nil)
Expand Down
9 changes: 5 additions & 4 deletions cm/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Copyright (c) 2024 Markus Stenberg
*
* Created: Fri Apr 26 14:09:03 2024 mstenber
* Last modified: Fri Apr 26 21:12:46 2024 mstenber
* Edit time: 6 min
* Last modified: Thu Oct 31 08:02:55 2024 mstenber
* Edit time: 7 min
*
*/

Expand All @@ -15,6 +15,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"log/slog"
"net/http"
"reflect"
)
Expand All @@ -32,10 +33,10 @@ func Parse(r CookieSource, u *URLWrapper, state any) (changed bool, err error) {
cookie, err := r.Cookie(name)
switch {
case err == http.ErrNoCookie:
// fmt.Printf("Cookie not found\n")
slog.Debug("Cookie not found")
err = nil
case err != nil:
// fmt.Printf("Failed to get cookie: %s", err)
slog.Warn("Failed to get cookie", "err", err)
return
case cookie != nil:
err = cookie.Valid()
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"fmt"
"io/fs"
"log"
"log/slog"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -145,9 +146,9 @@ func run(
Handler: mux,
}
go func() {
log.Printf("listening on %s\n", httpServer.Addr)
slog.Info("Listening", "addr", httpServer.Addr)
if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
fmt.Fprintf(os.Stderr, "error listening: %v", err)
slog.Error("Error listening", "err", err)
}
}()

Expand Down
7 changes: 4 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Copyright (c) 2024 Markus Stenberg
*
* Created: Thu May 16 07:24:25 2024 mstenber
* Last modified: Fri Jun 14 12:12:29 2024 mstenber
* Edit time: 32 min
* Last modified: Thu Oct 31 08:01:52 2024 mstenber
* Edit time: 33 min
*
*/

Expand All @@ -16,6 +16,7 @@ import (
"errors"
"fmt"
"log"
"log/slog"
"net/http"
"strconv"
"testing"
Expand All @@ -40,7 +41,7 @@ func waitForURL(ctx context.Context, url string) error {
if errors.Is(err, context.DeadlineExceeded) {
return err
}
fmt.Printf("Error making request: %v\n", err)
slog.Error("Error making request", "err", err)
continue
}
resp.Body.Close()
Expand Down

0 comments on commit 8043892

Please sign in to comment.