From aa5c7fc159b0f5175ede96d46b8d2a2669a176a4 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 28 Dec 2022 13:27:05 +0100 Subject: llog: use variable argument list Mirror more closely the fmt interface and reduce the verbosity of the log call sites. Additionally the log message is only created if we are actually going to log it. --- wrms.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'wrms.go') diff --git a/wrms.go b/wrms.go index ee3274c..816f491 100644 --- a/wrms.go +++ b/wrms.go @@ -2,7 +2,6 @@ package main import ( "encoding/json" - "fmt" "strings" "muhq.space/go/wrms/llog" @@ -31,7 +30,7 @@ func NewSongFromJson(data []byte) (Song, error) { var s Song err := json.Unmarshal(data, &s) if err != nil { - llog.Error(fmt.Sprintf("Failed to parse song data %s with %s", string(data), err)) + llog.Error("Failed to parse song data %s with %s", string(data), err) return s, err } @@ -52,7 +51,7 @@ type Connection struct { } func (c *Connection) Close() { - llog.Info(fmt.Sprintf("Closing connection %s", c.Id)) + llog.Info("Closing connection %s", c.Id) close(c.Events) c.C.Close(websocket.StatusNormalClosure, "") } @@ -82,7 +81,7 @@ func (wrms *Wrms) Close() { } func (wrms *Wrms) Broadcast(cmd Event) { - llog.Info(fmt.Sprintf("Broadcasting %v", cmd)) + llog.Info("Broadcasting %v", cmd) for i := 0; i < len(wrms.Connections); i++ { wrms.Connections[i].Events <- cmd } @@ -92,7 +91,7 @@ func (wrms *Wrms) AddSong(song Song) { wrms.Songs = append(wrms.Songs, song) s := &wrms.Songs[len(wrms.Songs)-1] wrms.queue.Add(s) - llog.Info(fmt.Sprintf("Added song %s (ptr=%p) to Songs", s.Uri, s)) + llog.Info("Added song %s (ptr=%p) to Songs", s.Uri, s) } func (wrms *Wrms) Next() { @@ -102,7 +101,7 @@ func (wrms *Wrms) Next() { return } - llog.Info(fmt.Sprintf("popped next song and removing it from the song list %v", next)) + llog.Info("popped next song and removing it from the song list %v", next) for i, s := range wrms.Songs { if s.Uri == wrms.CurrentSong.Uri { @@ -147,11 +146,11 @@ func (wrms *Wrms) AdjustSongWeight(connId string, songUri string, vote string) { continue } - llog.Info(fmt.Sprintf("Adjusting song %s (ptr=%p)", s.Uri, s)) + llog.Info("Adjusting song %s (ptr=%p)", s.Uri, s) switch vote { case "up": if _, ok := s.Upvotes[connId]; ok { - llog.Error(fmt.Sprintf("Double upvote of song %s by connections %s", songUri, connId)) + llog.Error("Double upvote of song %s by connections %s", songUri, connId) return } @@ -166,7 +165,7 @@ func (wrms *Wrms) AdjustSongWeight(connId string, songUri string, vote string) { case "down": if _, ok := s.Downvotes[connId]; ok { - llog.Error(fmt.Sprintf("Double downvote of song %s by connections %s", songUri, connId)) + llog.Error("Double downvote of song %s by connections %s", songUri, connId) return } @@ -189,7 +188,7 @@ func (wrms *Wrms) AdjustSongWeight(connId string, songUri string, vote string) { delete(s.Upvotes, connId) s.Weight -= 1 } else { - llog.Error(fmt.Sprintf("Double unvote of song %s by connections %s", songUri, connId)) + llog.Error("Double unvote of song %s by connections %s", songUri, connId) return } -- cgit v1.2.3