From 7bc490dc042be658620dc8fb40c437b077e28bff Mon Sep 17 00:00:00 2001 From: Konstantin Dudkov Date: Thu, 22 Aug 2024 13:29:52 +0300 Subject: [PATCH] slog --- cmd/goatak_server/admin_api.go | 8 ++++---- cmd/goatak_server/cert_api.go | 7 ++++--- cmd/goatak_server/http_server.go | 2 +- cmd/goatak_server/main.go | 6 +++--- cmd/goatak_server/marti_api.go | 19 ++++++++++--------- cmd/goatak_server/mission_api.go | 5 +++-- cmd/goatak_server/processors.go | 5 +++-- cmd/goatak_server/tak_ws/tak_ws.go | 2 +- cmd/goatak_server/tcpserver.go | 13 +++++++------ cmd/goatak_server/udpserver.go | 26 +++++++++++++++----------- cmd/mm/main.go | 2 +- cmd/webclient/api.go | 2 +- cmd/webclient/main.go | 4 ++-- cmd/webclient/processors.go | 3 ++- internal/client/client_handler.go | 8 ++++---- internal/client/enroll.go | 4 ++-- internal/pm/package_manager.go | 4 ++-- internal/repository/feeds_repo.go | 8 ++++---- internal/repository/user_repo.go | 8 ++++---- pkg/gpsd/gpsd.go | 10 +++++----- 20 files changed, 78 insertions(+), 68 deletions(-) diff --git a/cmd/goatak_server/admin_api.go b/cmd/goatak_server/admin_api.go index 2ecd084..691fd4b 100644 --- a/cmd/goatak_server/admin_api.go +++ b/cmd/goatak_server/admin_api.go @@ -246,7 +246,7 @@ func getCotPostHandler(app *App) fiber.Handler { c := new(cot.CotMessage) if err := json.Unmarshal(ctx.Body(), c); err != nil { - app.logger.Error("cot decode error", "error", err) + app.logger.Error("cot decode error", slog.Any("error", err)) return err } @@ -267,14 +267,14 @@ func getCotXMLPostHandler(app *App) fiber.Handler { ev := new(cot.Event) if err := xml.Unmarshal(ctx.Body(), &ev); err != nil { - app.logger.Error("cot decode error", "error", err) + app.logger.Error("cot decode error", slog.Any("error", err)) return err } c, err := cot.EventToProto(ev) if err != nil { - app.logger.Error("cot convert error", "error", err) + app.logger.Error("cot convert error", slog.Any("error", err)) return err } @@ -319,7 +319,7 @@ func getPackageHandler(app *App) fiber.Handler { f, err := app.packageManager.GetFile(pi.Hash) if err != nil { - app.logger.Error("get file error", "error", err) + app.logger.Error("get file error", slog.Any("error", err)) return err } diff --git a/cmd/goatak_server/cert_api.go b/cmd/goatak_server/cert_api.go index 83a346a..85a8275 100644 --- a/cmd/goatak_server/cert_api.go +++ b/cmd/goatak_server/cert_api.go @@ -5,6 +5,7 @@ import ( "crypto/rand" "crypto/x509" "fmt" + "log/slog" "math/big" "strings" "time" @@ -135,7 +136,7 @@ func getSignHandler(app *App) fiber.Handler { return func(ctx *fiber.Ctx) error { signedCert, err := app.processSignRequest(ctx) if err != nil { - app.logger.Error("error", "error", err.Error()) + app.logger.Error("error", slog.Any("error", err)) return err } @@ -147,7 +148,7 @@ func getSignHandler(app *App) fiber.Handler { p12Bytes, err := tlsutil.MakeP12TrustStore(certs, p12Password) if err != nil { - app.logger.Error("error making p12", "error", err) + app.logger.Error("error making p12", slog.Any("error", err)) return err } @@ -160,7 +161,7 @@ func getSignHandlerV2(app *App) fiber.Handler { return func(ctx *fiber.Ctx) error { signedCert, err := app.processSignRequest(ctx) if err != nil { - app.logger.Error("error", "error", err.Error()) + app.logger.Error("error", slog.Any("error", err)) return err } diff --git a/cmd/goatak_server/http_server.go b/cmd/goatak_server/http_server.go index 85078d1..bb4bdd0 100644 --- a/cmd/goatak_server/http_server.go +++ b/cmd/goatak_server/http_server.go @@ -57,7 +57,7 @@ func (h *HttpServer) Start() { h.log.Info(fmt.Sprintf("listening %s at %s", name, listener.Address())) if err := listener.Listen(); err != nil { - h.log.Error("error", "error", err.Error()) + h.log.Error("error", slog.Any("error", err)) panic(err) } }(name, listener) diff --git a/cmd/goatak_server/main.go b/cmd/goatak_server/main.go index 5bdfa63..16795d9 100644 --- a/cmd/goatak_server/main.go +++ b/cmd/goatak_server/main.go @@ -259,7 +259,7 @@ func (app *App) ConnectTo(ctx context.Context, addr string) { for ctx.Err() == nil { conn, err := app.connect(addr) if err != nil { - app.logger.Error("connect error", "error", err.Error()) + app.logger.Error("connect error", slog.Any("error", err)) time.Sleep(time.Second * 5) continue @@ -478,7 +478,7 @@ func (app *App) sendToCallsign(callsign string, msg *cot.CotMessage) { for _, c := range ch.GetUids() { if c == callsign { if err := ch.SendMsg(msg); err != nil { - app.logger.Error("error", "error", err) + app.logger.Error("send error", slog.Any("error", err)) } } } @@ -491,7 +491,7 @@ func (app *App) sendToUID(uid string, msg *cot.CotMessage) { app.ForAllClients(func(ch client.ClientHandler) bool { if ch.HasUID(uid) { if err := ch.SendMsg(msg); err != nil { - app.logger.Error("error", "error", err) + app.logger.Error("send error", slog.Any("error", err)) } } diff --git a/cmd/goatak_server/marti_api.go b/cmd/goatak_server/marti_api.go index 12b8e64..7767fbd 100644 --- a/cmd/goatak_server/marti_api.go +++ b/cmd/goatak_server/marti_api.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "strconv" "time" @@ -233,7 +234,7 @@ func getMissionUploadHandler(app *App) fiber.Handler { pi, err := app.uploadMultipart(ctx, "", hash, fname, true) if err != nil { - app.logger.Error("error", "error", err) + app.logger.Error("error", slog.Any("error", err)) return ctx.SendStatus(fiber.StatusNotAcceptable) } @@ -258,7 +259,7 @@ func getUploadHandler(app *App) fiber.Handler { case "multipart/form-data": pi, err := app.uploadMultipart(ctx, uid, "", fname, false) if err != nil { - app.logger.Error("error", "error", err) + app.logger.Error("error", slog.Any("error", err)) return ctx.SendStatus(fiber.StatusNotAcceptable) } @@ -267,7 +268,7 @@ func getUploadHandler(app *App) fiber.Handler { default: pi, err := app.uploadFile(ctx, uid, fname) if err != nil { - app.logger.Error("error", "error", err) + app.logger.Error("error", slog.Any("error", err)) return ctx.SendStatus(fiber.StatusNotAcceptable) } @@ -283,7 +284,7 @@ func (app *App) uploadMultipart(ctx *fiber.Ctx, uid, hash, filename string, pack fh, err := ctx.FormFile("assetfile") if err != nil { - app.logger.Error("error", "error", err) + app.logger.Error("error", slog.Any("error", err)) return nil, err } @@ -310,12 +311,12 @@ func (app *App) uploadMultipart(ctx *fiber.Ctx, uid, hash, filename string, pack f, err := fh.Open() if err != nil { - app.logger.Error("error", "error", err) + app.logger.Error("error", slog.Any("error", err)) return nil, err } if err := app.packageManager.SaveFile(pi, f); err != nil { - app.logger.Error("save file error", "error", err) + app.logger.Error("save file error", slog.Any("error", err)) return nil, err } @@ -342,7 +343,7 @@ func (app *App) uploadFile(ctx *fiber.Ctx, uid, filename string) (*pm.PackageInf } if err1 := app.packageManager.SaveFile(pi, ctx.Request().BodyStream()); err1 != nil { - app.logger.Error("save file error", "error", err1) + app.logger.Error("save file error", slog.Any("error", err1)) return nil, err1 } @@ -363,7 +364,7 @@ func getContentGetHandler(app *App) fiber.Handler { return ctx.Status(fiber.StatusNotFound).SendString("not found") } - app.logger.Error("get file error", "error", err) + app.logger.Error("get file error", slog.Any("error", err)) return err } @@ -386,7 +387,7 @@ func getContentGetHandler(app *App) fiber.Handler { f, err := app.packageManager.GetFile(pi.Hash) if err != nil { - app.logger.Error("get file error", "error", err) + app.logger.Error("get file error", slog.Any("error", err)) return err } diff --git a/cmd/goatak_server/mission_api.go b/cmd/goatak_server/mission_api.go index 7ff91a2..926c08f 100644 --- a/cmd/goatak_server/mission_api.go +++ b/cmd/goatak_server/mission_api.go @@ -4,6 +4,7 @@ import ( "encoding/json" "encoding/xml" "fmt" + "log/slog" "strings" "time" @@ -112,7 +113,7 @@ func getMissionPutHandler(app *App) fiber.Handler { } if err := app.missions.PutMission(m); err != nil { - app.logger.Warn("mission add error", "error", err.Error()) + app.logger.Warn("mission add error", slog.Any("error", err)) return ctx.Status(fiber.StatusConflict).SendString(err.Error()) } @@ -342,7 +343,7 @@ func getMissionCotHandler(app *App) fiber.Handler { for _, item := range mission.Items { if err := enc.Encode(cot.CotToEvent(item.GetEvent())); err != nil { - app.logger.Error("xml encode error", "error", err) + app.logger.Error("xml encode error", slog.Any("error", err)) } } diff --git a/cmd/goatak_server/processors.go b/cmd/goatak_server/processors.go index 49831f1..16d15c1 100644 --- a/cmd/goatak_server/processors.go +++ b/cmd/goatak_server/processors.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "log/slog" "os" "path/filepath" "strings" @@ -110,7 +111,7 @@ func (app *App) chatProcessor(msg *cot.CotMessage) bool { app.messages = append(app.messages, c) if err := logChatMessage(c); err != nil { - app.logger.Warn("error logging chat", "error", err.Error()) + app.logger.Warn("error logging chat", slog.Any("error", err)) } return true @@ -159,7 +160,7 @@ func (app *App) fileLoggerProcessor(msg *cot.CotMessage) bool { } if err := logMessage(msg, filepath.Join(app.config.dataDir, "log")); err != nil { - app.logger.Warn("error logging message", "error", err.Error()) + app.logger.Warn("error logging message", slog.Any("error", err)) } return true diff --git a/cmd/goatak_server/tak_ws/tak_ws.go b/cmd/goatak_server/tak_ws/tak_ws.go index 5e7d618..582357c 100644 --- a/cmd/goatak_server/tak_ws/tak_ws.go +++ b/cmd/goatak_server/tak_ws/tak_ws.go @@ -121,7 +121,7 @@ func (w *WsClientHandler) IsActive() bool { func (w *WsClientHandler) writer() { for b := range w.ch { if err := w.ws.WriteMessage(websocket.BinaryMessage, b); err != nil { - w.log.Error("send error", "error", err.Error()) + w.log.Error("send error", slog.Any("error", err)) w.Stop() break diff --git a/cmd/goatak_server/tcpserver.go b/cmd/goatak_server/tcpserver.go index 8893417..a20aa9d 100644 --- a/cmd/goatak_server/tcpserver.go +++ b/cmd/goatak_server/tcpserver.go @@ -4,6 +4,7 @@ import ( "context" "crypto/tls" "fmt" + "log/slog" "net" "time" @@ -15,13 +16,13 @@ func (app *App) ListenTCP(ctx context.Context, addr string) (err error) { app.logger.Info("listening TCP at " + addr) defer func() { if r := recover(); r != nil { - app.logger.Error("panic in ListenTCP", "error", r) + app.logger.Error("panic in ListenTCP", slog.Any("error", r)) } }() listener, err := net.Listen("tcp", addr) if err != nil { - app.logger.Error("Failed to listen", "error", err) + app.logger.Error("Failed to listen", slog.Any("error", err)) return err } @@ -31,7 +32,7 @@ func (app *App) ListenTCP(ctx context.Context, addr string) (err error) { for ctx.Err() == nil { conn, err := listener.Accept() if err != nil { - app.logger.Error("Unable to accept connections", "error", err) + app.logger.Error("Unable to accept connections", slog.Any("error", err)) return err } @@ -56,7 +57,7 @@ func (app *App) listenTLS(ctx context.Context, addr string) error { defer func() { if r := recover(); r != nil { - app.logger.Error("panic in ListenTLS", "error", r) + app.logger.Error("panic in ListenTLS", slog.Any("error", r)) } }() @@ -77,7 +78,7 @@ func (app *App) listenTLS(ctx context.Context, addr string) error { for ctx.Err() == nil { conn, err := listener.Accept() if err != nil { - app.logger.Error("Unable to accept connections", "error", err) + app.logger.Error("Unable to accept connections", slog.Any("error", err)) continue } @@ -95,7 +96,7 @@ func (app *App) processTLSConn(ctx context.Context, conn *tls.Conn) { defer cancel() if err := conn.HandshakeContext(ctx1); err != nil { - app.logger.Debug("Handshake error", "error", err) + app.logger.Debug("Handshake error", slog.Any("error", err)) _ = conn.Close() return diff --git a/cmd/goatak_server/udpserver.go b/cmd/goatak_server/udpserver.go index 382148b..564db2b 100644 --- a/cmd/goatak_server/udpserver.go +++ b/cmd/goatak_server/udpserver.go @@ -3,6 +3,7 @@ package main import ( "context" "encoding/xml" + "log/slog" "net" "google.golang.org/protobuf/proto" @@ -11,14 +12,17 @@ import ( "github.com/kdudkov/goatak/pkg/cotproto" ) -const magicByte = 0xbf +const ( + magicByte = 0xbf + scopeBroadcast = "broadcast" +) func (app *App) ListenUDP(ctx context.Context, addr string) error { app.logger.Info("listening UDP at " + addr) p, err := net.ListenPacket("udp", addr) if err != nil { - app.logger.Error("error", "error", err) + app.logger.Error("error", slog.Any("error", err)) return err } @@ -28,7 +32,7 @@ func (app *App) ListenUDP(ctx context.Context, addr string) error { for ctx.Err() == nil { n, _, err := p.ReadFrom(buf) if err != nil { - app.logger.Error("read error", "error", err) + app.logger.Error("read error", slog.Any("error", err)) return err } @@ -43,14 +47,14 @@ func (app *App) ListenUDP(ctx context.Context, addr string) error { err = proto.Unmarshal(buf[3:n], msg) if err != nil { - app.logger.Error("protobuf decode error", "error", err.Error()) + app.logger.Error("protobuf decode error", slog.Any("error", err)) continue } c, err := cot.CotFromProto(msg, "", cot.BroadcastScope) if err != nil { - app.logger.Error("protobuf detail extract error", "error", err.Error()) + app.logger.Error("protobuf detail extract error", slog.Any("error", err)) continue } @@ -61,14 +65,14 @@ func (app *App) ListenUDP(ctx context.Context, addr string) error { err = xml.Unmarshal(buf[3:n], ev) if err != nil { - app.logger.Error("xml decode error", "error", err.Error()) + app.logger.Error("xml decode error", slog.Any("error", err)) continue } - c, err := cot.EventToProtoExt(ev, "", "BROADCAST") + c, err := cot.EventToProtoExt(ev, "", scopeBroadcast) if err != nil { - app.logger.Error("error", "error", err.Error()) + app.logger.Error("error", slog.Any("error", err)) } app.NewCotMessage(c) @@ -76,14 +80,14 @@ func (app *App) ListenUDP(ctx context.Context, addr string) error { } else { ev := &cot.Event{} if err := xml.Unmarshal(buf[:n], ev); err != nil { - app.logger.Error("decode error", "error", err) + app.logger.Error("decode error", slog.Any("error", err)) continue } - c, err := cot.EventToProtoExt(ev, "", "broadcast") + c, err := cot.EventToProtoExt(ev, "", scopeBroadcast) if err != nil { - app.logger.Error("error", "error", err.Error()) + app.logger.Error("error", slog.Any("error", err)) } app.NewCotMessage(c) diff --git a/cmd/mm/main.go b/cmd/mm/main.go index 28457b0..419f17a 100644 --- a/cmd/mm/main.go +++ b/cmd/mm/main.go @@ -151,7 +151,7 @@ func (app *App) UI() { } if err := app.g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) { - app.Logger.Error("error", "error", err.Error()) + app.Logger.Error("error", slog.Any("error", err)) } } diff --git a/cmd/webclient/api.go b/cmd/webclient/api.go index e1fb94a..1f92493 100644 --- a/cmd/webclient/api.go +++ b/cmd/webclient/api.go @@ -75,7 +75,7 @@ func (app *App) periodicGetter(ctx context.Context) { case <-ticker.C: dat, err := app.remoteAPI.getContacts(ctx) if err != nil { - app.logger.Warn("error getting contacts", "error", err.Error()) + app.logger.Warn("error getting contacts", slog.Any("error", err)) continue } diff --git a/cmd/webclient/main.go b/cmd/webclient/main.go index 9412e30..435915e 100644 --- a/cmd/webclient/main.go +++ b/cmd/webclient/main.go @@ -142,7 +142,7 @@ func (app *App) Run(ctx context.Context) { for ctx.Err() == nil { conn, err := app.connect() if err != nil { - app.logger.Error("connect error", "error", err) + app.logger.Error("connect error", slog.Any("error", err)) time.Sleep(time.Second * 5) continue @@ -223,7 +223,7 @@ func (app *App) myPosSender(ctx context.Context, wg *sync.WaitGroup) { func (app *App) SendMsg(msg *cotproto.TakMessage) { if app.cl != nil { if err := app.cl.SendCot(msg); err != nil { - app.logger.Error("error", "error", err) + app.logger.Error("error", slog.Any("error", err)) } } } diff --git a/cmd/webclient/processors.go b/cmd/webclient/processors.go index fffa7d8..adb8735 100644 --- a/cmd/webclient/processors.go +++ b/cmd/webclient/processors.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "log/slog" "os" "strings" @@ -129,7 +130,7 @@ func (app *App) fileLoggerProcessor(msg *cot.CotMessage) { } if err := logMessage(msg, app.saveFile); err != nil { - app.logger.Warn("error logging message", "error", err.Error()) + app.logger.Warn("error logging message", slog.Any("error", err)) } } diff --git a/internal/client/client_handler.go b/internal/client/client_handler.go index 305227a..31607c1 100644 --- a/internal/client/client_handler.go +++ b/internal/client/client_handler.go @@ -172,7 +172,7 @@ func (h *ConnClientHandler) Start() { h.logger.Debug("send version msg") if err := h.sendEvent(cot.VersionSupportMsg(1)); err != nil { - h.logger.Error("error sending ver req", "error", err.Error()) + h.logger.Error("error sending ver req", slog.Any("error", err)) } } } @@ -187,7 +187,7 @@ func (h *ConnClientHandler) pinger(ctx context.Context) { h.logger.Debug("ping") if err := h.SendCot(cot.MakePing(h.localUID)); err != nil { - h.logger.Debug("sendMsg error", "error", err) + h.logger.Debug("sendMsg error", slog.Any("error", err)) } case <-ctx.Done(): return @@ -220,7 +220,7 @@ func (h *ConnClientHandler) handleRead(ctx context.Context) { break } - h.logger.Warn("error", "error", err.Error()) + h.logger.Warn("error", slog.Any("error", err)) break } @@ -256,7 +256,7 @@ func (h *ConnClientHandler) handleRead(ctx context.Context) { h.logger.Debug(fmt.Sprintf("ping from %s %s", h.addr, msg.GetUID())) if err := h.SendCot(cot.MakePong()); err != nil { - h.logger.Error("SendMsg error", "error", err) + h.logger.Error("SendMsg error", slog.Any("error", err)) } continue diff --git a/internal/client/enroll.go b/internal/client/enroll.go index dcb4a8a..5251263 100644 --- a/internal/client/enroll.go +++ b/internal/client/enroll.go @@ -166,14 +166,14 @@ func (e *Enroller) GetOrEnrollCert(ctx context.Context, uid, version string) (*t if e.save { if err := e.saveP12(key, cert, ca); err != nil { - e.logger.Error("error", "error", err.Error()) + e.logger.Error("error", slog.Any("error", err)) } } e.logger.Info("cert enrollment successful") if err := e.getProfile(ctx, uid); err != nil { - e.logger.Warn("error", "error", err.Error()) + e.logger.Warn("error", slog.Any("error", err)) } return &tls.Certificate{Certificate: [][]byte{cert.Raw}, PrivateKey: key, Leaf: cert}, ca, nil diff --git a/internal/pm/package_manager.go b/internal/pm/package_manager.go index 6928e27..707daef 100644 --- a/internal/pm/package_manager.go +++ b/internal/pm/package_manager.go @@ -55,7 +55,7 @@ func (pm *PackageManagerFS) Start() error { if pi, err := loadInfo(pm.baseDir, f.Name()); err == nil { pm.data.Store(uid, pi) } else { - pm.logger.Error("error loading info for "+uid, "error", err.Error()) + pm.logger.Error("error loading info for "+uid, slog.Any("error", err)) } } @@ -74,7 +74,7 @@ func (pm *PackageManagerFS) Store(pi *PackageInfo) { } if err := saveInfo(pm.baseDir, pi); err != nil { - pm.logger.Error("store error", "error", err.Error()) + pm.logger.Error("store error", slog.Any("error", err)) } } diff --git a/internal/repository/feeds_repo.go b/internal/repository/feeds_repo.go index 8176ccc..0fe8664 100644 --- a/internal/repository/feeds_repo.go +++ b/internal/repository/feeds_repo.go @@ -42,7 +42,7 @@ func (r *FeedsFileRepository) Store(f *model.Feed2) { fl, err := os.Create(filepath.Join(r.baseDir, f.UID+".yml")) if err != nil { - r.logger.Error("error", "error", err.Error()) + r.logger.Error("error", slog.Any("error", err)) return } @@ -51,7 +51,7 @@ func (r *FeedsFileRepository) Store(f *model.Feed2) { enc := yaml.NewEncoder(fl) if err := enc.Encode(f); err != nil { - r.logger.Error("error", "error", err.Error()) + r.logger.Error("error", slog.Any("error", err)) } } @@ -72,7 +72,7 @@ func (r *FeedsFileRepository) load(fname string) *model.Feed2 { dec := yaml.NewDecoder(fl) if err := dec.Decode(&f); err != nil { - r.logger.Error("error", "error", err.Error()) + r.logger.Error("error", slog.Any("error", err)) } f.Active = true @@ -87,7 +87,7 @@ func (r *FeedsFileRepository) Remove(uid string) { func (r *FeedsFileRepository) ForEach(f func(item *model.Feed2) bool) { files, err := os.ReadDir(r.baseDir) if err != nil { - r.logger.Error("error", "error", err.Error()) + r.logger.Error("error", slog.Any("error", err)) return } diff --git a/internal/repository/user_repo.go b/internal/repository/user_repo.go index 43b662b..439bca0 100644 --- a/internal/repository/user_repo.go +++ b/internal/repository/user_repo.go @@ -32,7 +32,7 @@ func NewFileUserRepo(userFile string) *UserFileRepository { } if err := um.loadUsersFile(); err != nil { - um.logger.Error("error loading users file", "error", err.Error()) + um.logger.Error("error loading users file", slog.Any("error", err)) } if len(um.users) == 0 { @@ -112,7 +112,7 @@ func (r *UserFileRepository) Start() error { r.logger.Info("users file is modified, reloading") if err := r.loadUsersFile(); err != nil { - r.logger.Error("error", "error", err.Error()) + r.logger.Error("error", slog.Any("error", err)) } } case err, ok := <-r.watcher.Errors: @@ -120,7 +120,7 @@ func (r *UserFileRepository) Start() error { return } - r.logger.Error("error", "error", err.Error()) + r.logger.Error("error", slog.Any("error", err)) } } }() @@ -141,7 +141,7 @@ func (r *UserFileRepository) CheckUserAuth(user, password string) bool { if user, ok := r.users[user]; ok { err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password)) if err != nil { - r.logger.Debug("password check failed", "error", err) + r.logger.Debug("password check failed", slog.Any("error", err)) return false } return true diff --git a/pkg/gpsd/gpsd.go b/pkg/gpsd/gpsd.go index 3ceeb72..4998223 100644 --- a/pkg/gpsd/gpsd.go +++ b/pkg/gpsd/gpsd.go @@ -87,7 +87,7 @@ func (c *GpsdClient) connect(ctx context.Context) bool { return true } - c.logger.Error("dial error", "error", err) + c.logger.Error("dial error", slog.Any("error", err)) select { case <-time.After(timeout): @@ -113,7 +113,7 @@ func (c *GpsdClient) Listen(ctx context.Context, cb func(lat, lon, alt, speed, t line, err := c.reader.ReadString('\n') if err != nil { - c.logger.Error("error", "error", err) + c.logger.Error("error", slog.Any("error", err)) _ = c.conn.Close() c.conn = nil @@ -125,7 +125,7 @@ func (c *GpsdClient) Listen(ctx context.Context, cb func(lat, lon, alt, speed, t var msg BaseMsg if err1 := json.Unmarshal(data, &msg); err1 != nil { - c.logger.Error("JSON decode error", "error", err1) + c.logger.Error("JSON decode error", slog.Any("error", err1)) c.logger.Debug("bad json: " + line) _ = c.conn.Close() c.conn = nil @@ -136,7 +136,7 @@ func (c *GpsdClient) Listen(ctx context.Context, cb func(lat, lon, alt, speed, t case "TPV": var r *TPVMsg if err1 := json.Unmarshal(data, &r); err1 != nil { - c.logger.Error("JSON decode error", "error", err1) + c.logger.Error("JSON decode error", slog.Any("error", err1)) } if cb != nil { @@ -145,7 +145,7 @@ func (c *GpsdClient) Listen(ctx context.Context, cb func(lat, lon, alt, speed, t case "VERSION": var r *VERSIONMsg if err1 := json.Unmarshal(data, &r); err1 != nil { - c.logger.Error("JSON decode error", "error", err1) + c.logger.Error("JSON decode error", slog.Any("error", err1)) } c.logger.Info(fmt.Sprintf("got version %s, rev. %s", r.Release, r.Rev)) }