From 4c3e4d56dde311e69954ddd219f259c956bfd385 Mon Sep 17 00:00:00 2001 From: Musilah Date: Wed, 24 Jan 2024 17:32:07 +0300 Subject: [PATCH] fix pages and log messages Signed-off-by: Musilah --- bootstrap/api/logging.go | 4 +-- certs/api/logging.go | 6 ++-- consumers/notifiers/api/logging.go | 1 + internal/groups/api/logging.go | 31 +++++++++++--------- lora/api/logging.go | 40 +++++++++++++------------- opcua/api/logging.go | 46 +++++++++++++----------------- pkg/messaging/handler/logging.go | 18 ++++++------ provision/api/logging.go | 2 ++ things/api/logging.go | 43 +++++++++++++++++----------- twins/api/logging.go | 12 ++++---- users/api/logging.go | 24 +++++++++++----- 11 files changed, 125 insertions(+), 102 deletions(-) diff --git a/bootstrap/api/logging.go b/bootstrap/api/logging.go index 17161c9f0..0d43d8fbb 100644 --- a/bootstrap/api/logging.go +++ b/bootstrap/api/logging.go @@ -107,7 +107,7 @@ func (lm *loggingMiddleware) UpdateConnections(ctx context.Context, token, id st defer func(begin time.Time) { args := []any{ slog.String("duration", time.Since(begin).String()), - slog.String("id", id), + slog.String("thing_id", id), } if err != nil { args = append(args, slog.Any("error", err)) @@ -243,7 +243,7 @@ func (lm *loggingMiddleware) RemoveChannelHandler(ctx context.Context, id string defer func(begin time.Time) { args := []any{ slog.String("duration", time.Since(begin).String()), - slog.String("id", id), + slog.String("channel_id", id), } if err != nil { args = append(args, slog.Any("error", err)) diff --git a/certs/api/logging.go b/certs/api/logging.go index c649809ee..d7f892540 100644 --- a/certs/api/logging.go +++ b/certs/api/logging.go @@ -55,6 +55,7 @@ func (lm *loggingMiddleware) ListCerts(ctx context.Context, token, thingID strin "page", slog.Uint64("offset", cp.Offset), slog.Uint64("limit", cp.Limit), + slog.Uint64("total", cp.Total), ), } if err != nil { @@ -79,14 +80,15 @@ func (lm *loggingMiddleware) ListSerials(ctx context.Context, token, thingID str "page", slog.Uint64("offset", cp.Offset), slog.Uint64("limit", cp.Limit), + slog.Uint64("total", cp.Total), ), } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("List certifcates failed to complete successfully", args...) + lm.logger.Warn("List certifcates serials failed to complete successfully", args...) return } - lm.logger.Info("List certificates completed successfully", args...) + lm.logger.Info("List certificates serials completed successfully", args...) }(time.Now()) return lm.svc.ListSerials(ctx, token, thingID, offset, limit) diff --git a/consumers/notifiers/api/logging.go b/consumers/notifiers/api/logging.go index 9cbc5b001..91b2c4562 100644 --- a/consumers/notifiers/api/logging.go +++ b/consumers/notifiers/api/logging.go @@ -82,6 +82,7 @@ func (lm *loggingMiddleware) ListSubscriptions(ctx context.Context, token string slog.String("topic", pm.Topic), slog.Int("limit", pm.Limit), slog.Uint64("offset", uint64(pm.Offset)), + slog.Uint64("total", uint64(res.Total)), ), } if err != nil { diff --git a/internal/groups/api/logging.go b/internal/groups/api/logging.go index 0bfbc2432..f57e4e1cd 100644 --- a/internal/groups/api/logging.go +++ b/internal/groups/api/logging.go @@ -115,13 +115,15 @@ func (lm *loggingMiddleware) ListGroups(ctx context.Context, token, memberKind, args := []any{ slog.String("duration", time.Since(begin).String()), slog.Group( - "group", - slog.String("member_kind", memberKind), - slog.String("member_id", memberID), - slog.Group( - "page", - slog.Uint64("limit", gp.Limit), - slog.Uint64("offset", gp.Offset)), + "member", + slog.String("id", memberID), + slog.String("kind", memberKind), + ), + slog.Group( + "page", + slog.Uint64("limit", gp.Limit), + slog.Uint64("offset", gp.Offset), + slog.Uint64("total", cg.Total), ), } if err != nil { @@ -162,7 +164,11 @@ func (lm *loggingMiddleware) DisableGroup(ctx context.Context, token, id string) defer func(begin time.Time) { args := []any{ slog.String("duration", time.Since(begin).String()), - slog.String("group_id", id), + slog.Group( + "group", + slog.String("id", id), + slog.String("name", g.Name), + ), } if err != nil { args = append(args, slog.Any("error", err)) @@ -180,12 +186,9 @@ func (lm *loggingMiddleware) ListMembers(ctx context.Context, token, groupID, pe defer func(begin time.Time) { args := []any{ slog.String("duration", time.Since(begin).String()), - slog.Group( - "group", - slog.String("id", groupID), - slog.String("permission", permission), - slog.String("member_kind", memberKind), - ), + slog.String("group_id", groupID), + slog.String("permission", permission), + slog.String("member_kind", memberKind), } if err != nil { args = append(args, slog.Any("error", err)) diff --git a/lora/api/logging.go b/lora/api/logging.go index 17a023197..dae317330 100644 --- a/lora/api/logging.go +++ b/lora/api/logging.go @@ -35,15 +35,15 @@ func (lm loggingMiddleware) CreateThing(ctx context.Context, thingID, loraDevEUI slog.Group( "thing", slog.String("id", thingID), - slog.String("dev_eui", loraDevEUI), ), + slog.String("dev_eui", loraDevEUI), } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Create thingID:devEUI route-map failed to complete successfully", args...) + lm.logger.Warn("Create thing %s and lora-dev-eui %s failed to complete successfully", args...) return } - lm.logger.Info("Create thingID:devEUI route-map completed successfully", args...) + lm.logger.Info("Create thing %s and lora-dev-eui %s completed successfully", args...) }(time.Now()) return lm.svc.CreateThing(ctx, thingID, loraDevEUI) @@ -56,15 +56,15 @@ func (lm loggingMiddleware) UpdateThing(ctx context.Context, thingID, loraDevEUI slog.Group( "thing", slog.String("id", thingID), - slog.String("dev_eui", loraDevEUI), ), + slog.String("dev_eui", loraDevEUI), } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Update thingID:devEUI route-map failed to complete successfully", args...) + lm.logger.Warn("Update thing %s and lora-dev-eui %s failed to complete successfully", args...) return } - lm.logger.Info("Update thingID:devEUI route-map completed successfully", args...) + lm.logger.Info("Update thing %s and lora-dev-eui %s completed successfully", args...) }(time.Now()) return lm.svc.UpdateThing(ctx, thingID, loraDevEUI) @@ -78,10 +78,10 @@ func (lm loggingMiddleware) RemoveThing(ctx context.Context, thingID string) (er } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Remove thingID:devEUI route-map failed to complete successfully", args...) + lm.logger.Warn("Remove thing failed to complete successfully", args...) return } - lm.logger.Info("Remove thingID:devEUI route-map completed successfully", args...) + lm.logger.Info("Remove thing completed successfully", args...) }(time.Now()) return lm.svc.RemoveThing(ctx, thingID) @@ -94,15 +94,15 @@ func (lm loggingMiddleware) CreateChannel(ctx context.Context, chanID, loraApp s slog.Group( "channel", slog.String("id", chanID), - slog.String("lora_app", loraApp), ), + slog.String("lora_app", loraApp), } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Create channelID:appID route-map failed to complete successfully", args...) + lm.logger.Warn("Create channel %s and lora-app %s failed to complete successfully", args...) return } - lm.logger.Info("Create channelID:appID route-map completed successfully", args...) + lm.logger.Info("Create channel %s and lora-app %s completed successfully", args...) }(time.Now()) return lm.svc.CreateChannel(ctx, chanID, loraApp) @@ -115,14 +115,14 @@ func (lm loggingMiddleware) UpdateChannel(ctx context.Context, chanID, loraApp s slog.Group( "channel", slog.String("id", chanID), - slog.String("lora_app", loraApp), ), + slog.String("lora_app", loraApp), } if err != nil { - lm.logger.Warn("Update channelID:appID route-map failed to complete successfully", args...) + lm.logger.Warn("Update channel %s and lora-app %s failed to complete successfully", args...) return } - lm.logger.Info("Update channelID:appID route-map completed successfully", args...) + lm.logger.Info("Update channel %s and lora-app %s route-map completed successfully", args...) }(time.Now()) return lm.svc.UpdateChannel(ctx, chanID, loraApp) @@ -135,10 +135,10 @@ func (lm loggingMiddleware) RemoveChannel(ctx context.Context, chanID string) (e slog.String("channel_id", chanID), } if err != nil { - lm.logger.Warn("Remove channelID:appID route-map failed to complete successfully", args...) + lm.logger.Warn("Remove channel failed to complete successfully", args...) return } - lm.logger.Info("Remove channelID:appID route-map completed successfully", args...) + lm.logger.Info("Remove channel completed successfully", args...) }(time.Now()) return lm.svc.RemoveChannel(ctx, chanID) @@ -153,10 +153,10 @@ func (lm loggingMiddleware) ConnectThing(ctx context.Context, chanID, thingID st } if err != nil { args := append(args, slog.String("error", err.Error())) - lm.logger.Warn("Connect thingID:channelID route-map failed to complete successfully", args...) + lm.logger.Warn("Connect thing for channel %s and thing %s failed to complete successfully", args...) return } - lm.logger.Info("Connect thingID:channelID route-map completed successfully", args...) + lm.logger.Info("Connect thing for channel %s and thing %s completed successfully", args...) }(time.Now()) return lm.svc.ConnectThing(ctx, chanID, thingID) @@ -171,10 +171,10 @@ func (lm loggingMiddleware) DisconnectThing(ctx context.Context, chanID, thingID } if err != nil { args := append(args, slog.String("error", err.Error())) - lm.logger.Warn("Disconnect thingID:channelID route-map failed to complete successfully", args...) + lm.logger.Warn("Disconnect thing for channel %s and thing %s failed to complete successfully", args...) return } - lm.logger.Info("Disconnect thingID:channelID route-map completed successfully", args...) + lm.logger.Info("Disconnect thing for channel %s and thing %s completed successfully", args...) }(time.Now()) return lm.svc.DisconnectThing(ctx, chanID, thingID) diff --git a/opcua/api/logging.go b/opcua/api/logging.go index 5b653cee9..1b5dd44c7 100644 --- a/opcua/api/logging.go +++ b/opcua/api/logging.go @@ -32,18 +32,15 @@ func (lm loggingMiddleware) CreateThing(ctx context.Context, mgxThing, opcuaNode defer func(begin time.Time) { args := []any{ slog.String("duration", time.Since(begin).String()), - slog.Group( - "thing", - slog.String("id", mgxThing), - slog.String("node_id", opcuaNodeID), - ), + slog.String("thing_id", mgxThing), + slog.String("node_id", opcuaNodeID), } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Create thingID:OPC-UA-nodeID route-map failed to complete successfully", args...) + lm.logger.Warn("Create thing %s with nodeID %s failed to complete successfully", args...) return } - lm.logger.Info("Create thingID:OPC-UA-nodeID route-map completed successfully", args...) + lm.logger.Info("Create thing %s with nodeID %s completed successfully", args...) }(time.Now()) return lm.svc.CreateThing(ctx, mgxThing, opcuaNodeID) @@ -53,18 +50,15 @@ func (lm loggingMiddleware) UpdateThing(ctx context.Context, mgxThing, opcuaNode defer func(begin time.Time) { args := []any{ slog.String("duration", time.Since(begin).String()), - slog.Group( - "thing", - slog.String("id", mgxThing), - slog.String("node_id", opcuaNodeID), - ), + slog.String("thing_id", mgxThing), + slog.String("node_id", opcuaNodeID), } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Update thingID:OPC-UA-nodeID route-map failed to complete successfully", args...) + lm.logger.Warn("Update thing %s with nodeID %s failed to complete successfully", args...) return } - lm.logger.Info("Update thingID:OPC-UA-nodeID route-map completed successfully", args...) + lm.logger.Info("Update thing %s with nodeID %s completed successfully", args...) }(time.Now()) return lm.svc.UpdateThing(ctx, mgxThing, opcuaNodeID) @@ -78,10 +72,10 @@ func (lm loggingMiddleware) RemoveThing(ctx context.Context, mgxThing string) (e } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Remove thingID:OPC-UA-nodeID route-map failed to complete successfully", args...) + lm.logger.Warn("Remove thing failed to complete successfully", args...) return } - lm.logger.Info("Remove thingID:OPC-UA-nodeID route-map completed successfully", args...) + lm.logger.Info("Remove thing completed successfully", args...) }(time.Now()) return lm.svc.RemoveThing(ctx, mgxThing) @@ -99,10 +93,10 @@ func (lm loggingMiddleware) CreateChannel(ctx context.Context, mgxChan, opcuaSer } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Create channelID:OPC-UA-serverURI route-map failed to complete successfully", args...) + lm.logger.Warn("Create channel %s with ServerURI %s failed to complete successfully", args...) return } - lm.logger.Info("Create channelID:OPC-UA-serverURI route-map completed successfully", args...) + lm.logger.Info("Create channel %s with ServerURI %s completed successfully", args...) }(time.Now()) return lm.svc.CreateChannel(ctx, mgxChan, opcuaServerURI) @@ -120,10 +114,10 @@ func (lm loggingMiddleware) UpdateChannel(ctx context.Context, mgxChanID, opcuaS } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Update channelID:OPC-UA-serverURI route-map failed to complete successfully", args...) + lm.logger.Warn("Update channel %s with ServerURI %s failed to complete successfully", args...) return } - lm.logger.Info("Update channelID:OPC-UA-serverURI route-map completed successfully", args...) + lm.logger.Info("Update channel %s with ServerURI %s completed successfully", args...) }(time.Now()) return lm.svc.UpdateChannel(ctx, mgxChanID, opcuaServerURI) @@ -137,10 +131,10 @@ func (lm loggingMiddleware) RemoveChannel(ctx context.Context, mgxChanID string) } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Remove channelID:OPC-UA-serverURI route-map failed to complete successfully", args...) + lm.logger.Warn("Remove channel %s failed to complete successfully", args...) return } - lm.logger.Info("Remove channelID:OPC-UA-serverURI route-map completed successfully", args...) + lm.logger.Info("Remove channel %s completed successfully", args...) }(time.Now()) return lm.svc.RemoveChannel(ctx, mgxChanID) @@ -155,10 +149,10 @@ func (lm loggingMiddleware) ConnectThing(ctx context.Context, mgxChanID, mgxThin } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Connect thingID:channelID route-map failed to complete successfully", args...) + lm.logger.Warn("Connect thing for channel %s and thing %s failed to complete successfully", args...) return } - lm.logger.Info("Connect thingID:channelID route-map completed successfully", args...) + lm.logger.Info("Connect thing for channel %s and thing %s completed successfully", args...) }(time.Now()) return lm.svc.ConnectThing(ctx, mgxChanID, mgxThingID) @@ -173,10 +167,10 @@ func (lm loggingMiddleware) DisconnectThing(ctx context.Context, mgxChanID, mgxT } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Disconnect thingID:channelID route-map failed to complete successfully", args...) + lm.logger.Warn("Disconnect thing for channel %s and thing %s failed to complete successfully", args...) return } - lm.logger.Info("Disconnect thingID:channelID route-map completed successfully", args...) + lm.logger.Info("Disconnect thing for channel %s and thing %s completed successfully", args...) }(time.Now()) return lm.svc.DisconnectThing(ctx, mgxChanID, mgxThingID) diff --git a/pkg/messaging/handler/logging.go b/pkg/messaging/handler/logging.go index d1dda91fa..6b92ca67b 100644 --- a/pkg/messaging/handler/logging.go +++ b/pkg/messaging/handler/logging.go @@ -22,43 +22,43 @@ type loggingMiddleware struct { // AuthConnect implements session.Handler. func (lm *loggingMiddleware) AuthConnect(ctx context.Context) (err error) { - return lm.logAction(ctx, "AuthConnect", nil, nil) + return lm.logAction(ctx, "AuthConnect", nil) } // AuthPublish implements session.Handler. func (lm *loggingMiddleware) AuthPublish(ctx context.Context, topic *string, payload *[]byte) (err error) { - return lm.logAction(ctx, "AuthPublish", &[]string{*topic}, payload) + return lm.logAction(ctx, "AuthPublish", &[]string{*topic}) } // AuthSubscribe implements session.Handler. func (lm *loggingMiddleware) AuthSubscribe(ctx context.Context, topics *[]string) (err error) { - return lm.logAction(ctx, "AuthSubscribe", topics, nil) + return lm.logAction(ctx, "AuthSubscribe", topics) } // Connect implements session.Handler. func (lm *loggingMiddleware) Connect(ctx context.Context) (err error) { - return lm.logAction(ctx, "Connect", nil, nil) + return lm.logAction(ctx, "Connect", nil) } // Disconnect implements session.Handler. func (lm *loggingMiddleware) Disconnect(ctx context.Context) (err error) { - return lm.logAction(ctx, "Disconnect", nil, nil) + return lm.logAction(ctx, "Disconnect", nil) } // Publish logs the publish request. It logs the time it took to complete the request. // If the request fails, it logs the error. func (lm *loggingMiddleware) Publish(ctx context.Context, topic *string, payload *[]byte) (err error) { - return lm.logAction(ctx, "Publish", &[]string{*topic}, payload) + return lm.logAction(ctx, "Publish", &[]string{*topic}) } // Subscribe implements session.Handler. func (lm *loggingMiddleware) Subscribe(ctx context.Context, topics *[]string) (err error) { - return lm.logAction(ctx, "Subscribe", topics, nil) + return lm.logAction(ctx, "Subscribe", topics) } // Unsubscribe implements session.Handler. func (lm *loggingMiddleware) Unsubscribe(ctx context.Context, topics *[]string) (err error) { - return lm.logAction(ctx, "Unsubscribe", topics, nil) + return lm.logAction(ctx, "Unsubscribe", topics) } // LoggingMiddleware adds logging facilities to the adapter. @@ -66,7 +66,7 @@ func LoggingMiddleware(svc session.Handler, logger *slog.Logger) session.Handler return &loggingMiddleware{logger, svc} } -func (lm *loggingMiddleware) logAction(ctx context.Context, action string, topics *[]string, payload *[]byte) (err error) { +func (lm *loggingMiddleware) logAction(ctx context.Context, action string, topics *[]string) (err error) { defer func(begin time.Time) { args := []any{ slog.String("duration", time.Since(begin).String()), diff --git a/provision/api/logging.go b/provision/api/logging.go index 038f3688b..f6f6a9f63 100644 --- a/provision/api/logging.go +++ b/provision/api/logging.go @@ -28,6 +28,7 @@ func (lm *loggingMiddleware) Provision(token, name, externalID, externalKey stri defer func(begin time.Time) { args := []any{ slog.String("duration", time.Since(begin).String()), + slog.String("external_id", externalID), } if err != nil { args = append(args, slog.Any("error", err)) @@ -45,6 +46,7 @@ func (lm *loggingMiddleware) Cert(token, thingID, duration string) (cert, key st args := []any{ slog.String("duration", time.Since(begin).String()), slog.String("thing_id", thingID), + slog.String("ttl", duration), } if err != nil { args = append(args, slog.Any("error", err)) diff --git a/things/api/logging.go b/things/api/logging.go index 0c3992054..f78b46e6c 100644 --- a/things/api/logging.go +++ b/things/api/logging.go @@ -44,7 +44,7 @@ func (lm *loggingMiddleware) ViewClient(ctx context.Context, token, id string) ( defer func(begin time.Time) { args := []any{ slog.String("duration", time.Since(begin).String()), - slog.String("id", id), + slog.Group("thing", slog.String("id", c.ID), slog.String("name", c.Name)), } if err != nil { args = append(args, slog.Any("error", err)) @@ -60,7 +60,7 @@ func (lm *loggingMiddleware) ViewClientPerms(ctx context.Context, token, id stri defer func(begin time.Time) { args := []any{ slog.String("duration", time.Since(begin).String()), - slog.String("id", id), + slog.String("thing_id", id), } if err != nil { args = append(args, slog.Any("error", err)) @@ -99,7 +99,7 @@ func (lm *loggingMiddleware) UpdateClient(ctx context.Context, token string, cli args := []any{ slog.String("duration", time.Since(begin).String()), slog.Group( - "client", + "thing", slog.String("id", client.ID), slog.String("name", client.Name), slog.Any("metadata", client.Metadata), @@ -120,7 +120,7 @@ func (lm *loggingMiddleware) UpdateClientTags(ctx context.Context, token string, args := []any{ slog.String("duration", time.Since(begin).String()), slog.Group( - "client", + "thing", slog.String("id", client.ID), slog.Any("tags", client.Tags), ), @@ -140,8 +140,9 @@ func (lm *loggingMiddleware) UpdateClientSecret(ctx context.Context, token, oldS args := []any{ slog.String("duration", time.Since(begin).String()), slog.Group( - "things", + "thing", slog.String("id", c.ID), + slog.String("name", c.Name), ), } if err != nil { @@ -158,7 +159,11 @@ func (lm *loggingMiddleware) EnableClient(ctx context.Context, token, id string) defer func(begin time.Time) { args := []any{ slog.String("duration", time.Since(begin).String()), - slog.String("id", id), + slog.Group( + "thing", + slog.String("id", id), + slog.String("name", c.Name), + ), } if err != nil { args = append(args, slog.Any("error", err)) @@ -174,7 +179,11 @@ func (lm *loggingMiddleware) DisableClient(ctx context.Context, token, id string defer func(begin time.Time) { args := []any{ slog.String("duration", time.Since(begin).String()), - slog.String("id", id), + slog.Group( + "thing", + slog.String("thing_id", id), + slog.String("name", c.Name), + ), } if err != nil { args = append(args, slog.Any("error", err)) @@ -212,10 +221,7 @@ func (lm *loggingMiddleware) Identify(ctx context.Context, key string) (id strin defer func(begin time.Time) { args := []any{ slog.String("duration", time.Since(begin).String()), - slog.Group( - "thing", - slog.String("id", id), - ), + slog.String("thing_id", id), } if err != nil { args = append(args, slog.Any("error", err)) @@ -231,8 +237,11 @@ func (lm *loggingMiddleware) Authorize(ctx context.Context, req *magistrala.Auth defer func(begin time.Time) { args := []any{ slog.String("duration", time.Since(begin).String()), - slog.String("thing_key", req.GetSubject()), - slog.String("channel_id", req.GetObject()), + slog.String("object", req.GetObject()), + slog.String("object_type", req.GetObjectType()), + slog.String("subject", req.GetSubject()), + slog.String("subject_type", req.GetSubjectType()), + slog.String("permission", req.GetPermission()), } if err != nil { args = append(args, slog.Any("error", err)) @@ -254,10 +263,10 @@ func (lm *loggingMiddleware) Share(ctx context.Context, token, id, relation stri } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Share failed to complete successfully", args...) + lm.logger.Warn("Share thing failed to complete successfully", args...) return } - lm.logger.Info("Share completed successfully", args...) + lm.logger.Info("Share thing completed successfully", args...) }(time.Now()) return lm.svc.Share(ctx, token, id, relation, userids...) } @@ -272,10 +281,10 @@ func (lm *loggingMiddleware) Unshare(ctx context.Context, token, id, relation st } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Unshare failed to complete successfully", args...) + lm.logger.Warn("Unshare thing failed to complete successfully", args...) return } - lm.logger.Info("Unshare completed successfully", args...) + lm.logger.Info("Unshare thing completed successfully", args...) }(time.Now()) return lm.svc.Unshare(ctx, token, id, relation, userids...) } diff --git a/twins/api/logging.go b/twins/api/logging.go index 6867eda78..fd23556c1 100644 --- a/twins/api/logging.go +++ b/twins/api/logging.go @@ -34,7 +34,7 @@ func (lm *loggingMiddleware) AddTwin(ctx context.Context, token string, twin twi "twin", slog.String("id", tw.ID), slog.String("name", tw.Name), - slog.Group("definition", slog.Any("def_id", def.ID)), + slog.Any("definitions", tw.Definitions), ), } if err != nil { @@ -56,7 +56,7 @@ func (lm *loggingMiddleware) UpdateTwin(ctx context.Context, token string, twin "twin", slog.String("id", twin.ID), slog.String("name", twin.Name), - slog.Group("definition", slog.Any("def_id", def.ID)), + slog.Any("definitions", def), ), } if err != nil { @@ -96,6 +96,7 @@ func (lm *loggingMiddleware) ListTwins(ctx context.Context, token string, offset slog.String("name", name), slog.Uint64("offset", offset), slog.Uint64("limit", limit), + slog.Uint64("total", page.Total), ), } if err != nil { @@ -115,9 +116,9 @@ func (lm *loggingMiddleware) SaveStates(ctx context.Context, msg *messaging.Mess slog.String("duration", time.Since(begin).String()), slog.Group( "message", - slog.String("subtopic", msg.Subtopic), - slog.String("channel", msg.Channel), - slog.String("publisher", msg.Publisher), + slog.String("subtopic", msg.GetSubtopic()), + slog.String("channel", msg.GetChannel()), + slog.String("publisher", msg.GetPublisher()), ), } if err != nil { @@ -140,6 +141,7 @@ func (lm *loggingMiddleware) ListStates(ctx context.Context, token string, offse "page", slog.Uint64("offset", offset), slog.Uint64("limit", limit), + slog.Uint64("total", page.Total), ), } if err != nil { diff --git a/users/api/logging.go b/users/api/logging.go index b734f0279..800719be1 100644 --- a/users/api/logging.go +++ b/users/api/logging.go @@ -5,7 +5,6 @@ package api import ( "context" - "fmt" "log/slog" "time" @@ -169,7 +168,7 @@ func (lm *loggingMiddleware) UpdateClientTags(ctx context.Context, token string, defer func(begin time.Time) { args := []any{ slog.String("duration", time.Since(begin).String()), - slog.Group("user", slog.String("id", c.ID), slog.Any("tags", fmt.Sprintf("%v", c.Tags))), + slog.Group("user", slog.String("id", c.ID), slog.Any("tags", c.Tags)), } if err != nil { args = append(args, slog.Any("error", err)) @@ -294,7 +293,11 @@ func (lm *loggingMiddleware) EnableClient(ctx context.Context, token, id string) defer func(begin time.Time) { args := []any{ slog.String("duration", time.Since(begin).String()), - slog.String("id", c.ID), + slog.Group( + "user", + slog.String("id", c.ID), + slog.String("name", c.Name), + ), } if err != nil { args = append(args, slog.Any("error", err)) @@ -312,7 +315,11 @@ func (lm *loggingMiddleware) DisableClient(ctx context.Context, token, id string defer func(begin time.Time) { args := []any{ slog.String("duration", time.Since(begin).String()), - slog.String("id", c.ID), + slog.Group( + "user", + slog.String("id", c.ID), + slog.String("name", c.Name), + ), } if err != nil { args = append(args, slog.Any("error", err)) @@ -330,7 +337,10 @@ func (lm *loggingMiddleware) ListMembers(ctx context.Context, token, objectKind, defer func(begin time.Time) { args := []any{ slog.String("duration", time.Since(begin).String()), - slog.Group("object", slog.String("kind", objectKind), slog.String("id", objectID)), + slog.Group("object", + slog.String("kind", objectKind), + slog.String("id", objectID), + ), slog.Group( "page", slog.Uint64("limit", cp.Limit), @@ -356,10 +366,10 @@ func (lm *loggingMiddleware) Identify(ctx context.Context, token string) (id str } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Identify failed to complete successfully", args...) + lm.logger.Warn("Identify user failed to complete successfully", args...) return } - lm.logger.Info("Identify completed successfully", args...) + lm.logger.Info("Identify user completed successfully", args...) }(time.Now()) return lm.svc.Identify(ctx, token) }