X-Git-Url: http://git.giacomolli.uk/onechat/blobdiff_plain/7088b82414bdf947a6f88918c0a7b2c7fb0c53ef..refs/heads/master:/whatsapp_groups.go?ds=inline diff --git a/whatsapp_groups.go b/whatsapp_groups.go index c8d066a..ec5c892 100644 --- a/whatsapp_groups.go +++ b/whatsapp_groups.go @@ -2,7 +2,7 @@ package main import ( "context" - "log" + "log/slog" "maps" "sync" "time" @@ -23,7 +23,7 @@ const ( // newWhatsAppGroups returns the names of the groups with no names yet. logger // gets the failures of a read. -func newWhatsAppGroups(logger *log.Logger) *WhatsAppGroups { +func newWhatsAppGroups(logger *slog.Logger) *WhatsAppGroups { return &WhatsAppGroups{ logger: logger, names: make(map[string]string), @@ -36,7 +36,7 @@ func newWhatsAppGroups(logger *log.Logger) *WhatsAppGroups { // read, and readAt the time of the last read that succeeded. The mutex // protects all fields after logger. type WhatsAppGroups struct { - logger *log.Logger + logger *slog.Logger mutex sync.Mutex names map[string]string @@ -49,6 +49,7 @@ type WhatsAppGroups struct { // again, at most once in whatsappGroupsRefresh. func (g *WhatsAppGroups) name(ctx context.Context, link WhatsAppLink, id string) string { g.mutex.Lock() + name, found := g.names[id] fresh := time.Since(g.triedAt) < whatsappGroupsRefresh g.mutex.Unlock() @@ -57,6 +58,7 @@ func (g *WhatsAppGroups) name(ctx context.Context, link WhatsAppLink, id string) g.read(ctx, link) g.mutex.Lock() + name, found = g.names[id] g.mutex.Unlock() } @@ -80,7 +82,7 @@ func (g *WhatsAppGroups) read(ctx context.Context, link WhatsAppLink) bool { groups, err := link.client.GetJoinedGroups(ctx) if err != nil { - g.logger.Printf("group list failed: %s", whatsappRedact(link.own, err.Error())) + g.logger.Warn("group list failed", "err", whatsappRedact(link.own, err.Error())) } g.mutex.Lock()