diff --git a/auth/api/logging.go b/auth/api/logging.go index 377174465..a4f931ae8 100644 --- a/auth/api/logging.go +++ b/auth/api/logging.go @@ -381,8 +381,9 @@ func (lm *loggingMiddleware) ListDomains(ctx context.Context, token string, page slog.String("duration", time.Since(begin).String()), slog.Group( "page", - slog.Any("limit", page.Limit), - slog.Any("offset", page.Offset), + slog.Uint64("limit", page.Limit), + slog.Uint64("offset", page.Offset), + slog.Uint64("total", page.Total), ), } if err != nil { diff --git a/coap/api/logging.go b/coap/api/logging.go index 758b26ab3..23114f6c3 100644 --- a/coap/api/logging.go +++ b/coap/api/logging.go @@ -32,7 +32,6 @@ func (lm *loggingMiddleware) Publish(ctx context.Context, key string, msg *messa defer func(begin time.Time) { args := []interface{}{ slog.String("duration", time.Since(begin).String()), - slog.String("key", key), } destChannel := msg.GetChannel() if msg.GetSubtopic() != "" { @@ -55,11 +54,10 @@ func (lm *loggingMiddleware) Subscribe(ctx context.Context, key, chanID, subtopi defer func(begin time.Time) { args := []interface{}{ slog.String("duration", time.Since(begin).String()), - slog.String("key", key), + slog.String("channel_id", chanID), } - destChannel := chanID if subtopic != "" { - args = append(args, slog.String("subtopic", subtopic), slog.String("channel", destChannel)) + args = append(args, slog.String("subtopic", subtopic)) } if err != nil { args = append(args, slog.Any("error", err)) @@ -78,11 +76,10 @@ func (lm *loggingMiddleware) Unsubscribe(ctx context.Context, key, chanID, subto defer func(begin time.Time) { args := []interface{}{ slog.String("duration", time.Since(begin).String()), - slog.String("key", key), + slog.String("channel_id", chanID), } - destChannel := chanID if subtopic != "" { - args = append(args, slog.String("subtopic", subtopic), slog.String("channel", destChannel)) + args = append(args, slog.String("subtopic", subtopic)) } if err != nil { args = append(args, slog.Any("error", err)) diff --git a/consumers/notifiers/api/logging.go b/consumers/notifiers/api/logging.go index 145151fc1..cb31f11b2 100644 --- a/consumers/notifiers/api/logging.go +++ b/consumers/notifiers/api/logging.go @@ -80,7 +80,7 @@ func (lm *loggingMiddleware) ListSubscriptions(ctx context.Context, token string slog.Group( "page_metadata", slog.String("topic", pm.Topic), - slog.Any("limit", pm.Limit), + slog.Int("limit", pm.Limit), slog.Any("offset", pm.Offset), ), } diff --git a/internal/groups/api/logging.go b/internal/groups/api/logging.go index 25c428c45..ff79d45c3 100644 --- a/internal/groups/api/logging.go +++ b/internal/groups/api/logging.go @@ -121,8 +121,8 @@ func (lm *loggingMiddleware) ListGroups(ctx context.Context, token, memberKind, slog.String("member_id", memberID), slog.Group( "page", - slog.Any("limit", gp.Limit), - slog.Any("offset", gp.Offset)), + slog.Uint64("limit", gp.Limit), + slog.Uint64("offset", gp.Offset)), ), } if err != nil { diff --git a/provision/api/logging.go b/provision/api/logging.go index 9d7a96afd..b4617f8ee 100644 --- a/provision/api/logging.go +++ b/provision/api/logging.go @@ -28,9 +28,6 @@ func (lm *loggingMiddleware) Provision(token, name, externalID, externalKey stri defer func(begin time.Time) { args := []interface{}{ slog.String("duration", time.Since(begin).String()), - slog.String("name", name), - slog.String("external_id", externalID), - slog.String("external_key", externalKey), } if err != nil { args = append(args, slog.Any("error", err)) @@ -48,14 +45,13 @@ func (lm *loggingMiddleware) Cert(token, thingID, duration string) (cert, key st args := []interface{}{ slog.String("duration", time.Since(begin).String()), slog.String("thing_id", thingID), - slog.String("duration", duration), } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Cert failed to complete successfully", args...) + lm.logger.Warn("Thing certificate failed to create successfully", args...) return } - lm.logger.Info("Cert completed successfully", args...) + lm.logger.Info("Thing certificate completed successfully", args...) }(time.Now()) return lm.svc.Cert(token, thingID, duration) diff --git a/readers/api/logging.go b/readers/api/logging.go index 1f55d4d18..01df750e2 100644 --- a/readers/api/logging.go +++ b/readers/api/logging.go @@ -31,11 +31,12 @@ func (lm *loggingMiddleware) ReadAll(chanID string, rpm readers.PageMetadata) (p defer func(begin time.Time) { args := []interface{}{ slog.String("duration", time.Since(begin).String()), - slog.String("channel_ID", chanID), + slog.String("channel_id", chanID), slog.Group( "page_metadata", - slog.Any("offset", rpm.Offset), - slog.Any("limit", rpm.Limit), + slog.Uint64("offset", rpm.Offset), + slog.Uint64("limit", rpm.Limit), + slog.Uint64("total", page.Total), slog.String("subtopic", rpm.Subtopic), slog.String("publisher", rpm.Publisher), ), diff --git a/things/api/logging.go b/things/api/logging.go index d1ce8c279..d83f91f3b 100644 --- a/things/api/logging.go +++ b/things/api/logging.go @@ -27,7 +27,8 @@ func LoggingMiddleware(svc things.Service, logger *slog.Logger) things.Service { func (lm *loggingMiddleware) CreateThings(ctx context.Context, token string, clients ...mgclients.Client) (cs []mgclients.Client, err error) { defer func(begin time.Time) { args := []interface{}{ - slog.String("duration", time.Since(begin).String()), slog.Any("no_of_things", len(clients)), + slog.String("duration", time.Since(begin).String()), + slog.Any("no_of_things", len(clients)), } if err != nil { args = append(args, slog.Any("error", err)) @@ -47,10 +48,10 @@ func (lm *loggingMiddleware) ViewClient(ctx context.Context, token, id string) ( } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("View client failed to complete successfully", args...) + lm.logger.Warn("View thing failed to complete successfully", args...) return } - lm.logger.Info("View client completed successfully", args...) + lm.logger.Info("View thing completed successfully", args...) }(time.Now()) return lm.svc.ViewClient(ctx, token, id) } @@ -63,10 +64,10 @@ func (lm *loggingMiddleware) ViewClientPerms(ctx context.Context, token, id stri } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("View client permissions failed to complete successfully", args...) + lm.logger.Warn("View thing permissions failed to complete successfully", args...) return } - lm.logger.Info("View client permissions completed successfully", args...) + lm.logger.Info("View thing permissions completed successfully", args...) }(time.Now()) return lm.svc.ViewClientPerms(ctx, token, id) } @@ -78,16 +79,17 @@ func (lm *loggingMiddleware) ListClients(ctx context.Context, token, reqUserID s slog.String("user_id", reqUserID), slog.Group( "page", - slog.Any("limit", pm.Limit), - slog.Any("offset", pm.Offset), + slog.Uint64("limit", pm.Limit), + slog.Uint64("offset", pm.Offset), + slog.Uint64("total", cp.Total), ), } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("List clients failed to complete successfully", args...) + lm.logger.Warn("List things failed to complete successfully", args...) return } - lm.logger.Info("List clients completed successfully", args...) + lm.logger.Info("List things completed successfully", args...) }(time.Now()) return lm.svc.ListClients(ctx, token, reqUserID, pm) } @@ -105,10 +107,10 @@ func (lm *loggingMiddleware) UpdateClient(ctx context.Context, token string, cli } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Update client failed to complete successfully", args...) + lm.logger.Warn("Update thing failed to complete successfully", args...) return } - lm.logger.Info("Update client completed successfully", args...) + lm.logger.Info("Update thing completed successfully", args...) }(time.Now()) return lm.svc.UpdateClient(ctx, token, client) } @@ -125,10 +127,10 @@ func (lm *loggingMiddleware) UpdateClientTags(ctx context.Context, token string, } if err != nil { args := append(args, slog.String("error", err.Error())) - lm.logger.Warn("Update client tags failed to complete successfully", args...) + lm.logger.Warn("Update thing tags failed to complete successfully", args...) return } - lm.logger.Info("Update client tags completed successfully", args...) + lm.logger.Info("Update thing tags completed successfully", args...) }(time.Now()) return lm.svc.UpdateClientTags(ctx, token, client) } @@ -144,10 +146,10 @@ func (lm *loggingMiddleware) UpdateClientSecret(ctx context.Context, token, oldS } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Update client secret failed to complete successfully", args...) + lm.logger.Warn("Update thing secret failed to complete successfully", args...) return } - lm.logger.Info("Update client secret completed successfully", args...) + lm.logger.Info("Update thing secret completed successfully", args...) }(time.Now()) return lm.svc.UpdateClientSecret(ctx, token, oldSecret, newSecret) } @@ -160,10 +162,10 @@ func (lm *loggingMiddleware) EnableClient(ctx context.Context, token, id string) } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Enable client failed to complete successfully", args...) + lm.logger.Warn("Enable thing failed to complete successfully", args...) return } - lm.logger.Info("Enable client completed successfully", args...) + lm.logger.Info("Enable thing completed successfully", args...) }(time.Now()) return lm.svc.EnableClient(ctx, token, id) } @@ -176,10 +178,10 @@ func (lm *loggingMiddleware) DisableClient(ctx context.Context, token, id string } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Disable client failed to complete successfully", args...) + lm.logger.Warn("Disable thing failed to complete successfully", args...) return } - lm.logger.Info("Disable client completed successfully", args...) + lm.logger.Info("Disable thing completed successfully", args...) }(time.Now()) return lm.svc.DisableClient(ctx, token, id) } @@ -191,16 +193,17 @@ func (lm *loggingMiddleware) ListClientsByGroup(ctx context.Context, token, chan slog.String("channel_id", channelID), slog.Group( "page", - slog.Any("offset", cp.Offset), - slog.Any("limit", cp.Limit), + slog.Uint64("offset", cp.Offset), + slog.Uint64("limit", cp.Limit), + slog.Uint64("total", mp.Total), ), } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("List clients by group failed to complete successfully", args...) + lm.logger.Warn("List things by group failed to complete successfully", args...) return } - lm.logger.Info("List clients by group completed successfully", args...) + lm.logger.Info("List things by group completed successfully", args...) }(time.Now()) return lm.svc.ListClientsByGroup(ctx, token, channelID, cp) } @@ -211,16 +214,15 @@ func (lm *loggingMiddleware) Identify(ctx context.Context, key string) (id strin slog.String("duration", time.Since(begin).String()), slog.Group( "thing", - slog.String("key", key), slog.String("id", id), ), } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Identify failed to complete successfully", args...) + lm.logger.Warn("Identify thing failed to complete successfully", args...) return } - lm.logger.Info("Identify completed successfully", args...) + lm.logger.Info("Identify thing completed successfully", args...) }(time.Now()) return lm.svc.Identify(ctx, key) } @@ -286,10 +288,10 @@ func (lm *loggingMiddleware) DeleteClient(ctx context.Context, token, id string) } if err != nil { args = append(args, slog.Any("error", err)) - lm.logger.Warn("Delete client failed to complete successfully", args...) + lm.logger.Warn("Delete thing failed to complete successfully", args...) return } - lm.logger.Info("Delete client completed successfully", args...) + lm.logger.Info("Delete thing completed successfully", args...) }(time.Now()) return lm.svc.DeleteClient(ctx, token, id) } diff --git a/twins/api/logging.go b/twins/api/logging.go index f8ecde1ea..b7570df55 100644 --- a/twins/api/logging.go +++ b/twins/api/logging.go @@ -32,8 +32,8 @@ func (lm *loggingMiddleware) AddTwin(ctx context.Context, token string, twin twi slog.String("duration", time.Since(begin).String()), slog.Group( "twin", - slog.String("id", twin.ID), - slog.String("name", twin.Name), + slog.String("id", tw.ID), + slog.String("name", tw.Name), slog.Group("definition", slog.Any("def_id", def.ID)), ), } @@ -114,7 +114,7 @@ func (lm *loggingMiddleware) SaveStates(ctx context.Context, msg *messaging.Mess args := []interface{}{ slog.String("duration", time.Since(begin).String()), slog.Group( - "payload", + "message", slog.String("subtopic", msg.Subtopic), slog.String("channel", msg.Channel), slog.String("publisher", msg.Publisher), diff --git a/users/api/logging.go b/users/api/logging.go index 04597b764..4979caa6a 100644 --- a/users/api/logging.go +++ b/users/api/logging.go @@ -32,7 +32,7 @@ func (lm *loggingMiddleware) RegisterClient(ctx context.Context, token string, c defer func(begin time.Time) { args := []interface{}{ slog.String("duration", time.Since(begin).String()), - slog.Group("user", slog.String("name", c.Name), 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)) @@ -92,7 +92,7 @@ func (lm *loggingMiddleware) ViewClient(ctx context.Context, token, id string) ( defer func(begin time.Time) { args := []interface{}{ slog.String("duration", time.Since(begin).String()), - slog.Group("user", slog.String("name", c.Name), slog.String("id", id)), + slog.Group("user", slog.String("id", id), slog.String("name", c.Name),), } if err != nil { args = append(args, slog.Any("error", err)) @@ -110,7 +110,7 @@ func (lm *loggingMiddleware) ViewProfile(ctx context.Context, token string) (c m defer func(begin time.Time) { args := []interface{}{ slog.String("duration", time.Since(begin).String()), - slog.Group("user", slog.String("name", c.Name), 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)) @@ -130,8 +130,9 @@ func (lm *loggingMiddleware) ListClients(ctx context.Context, token string, pm m slog.String("duration", time.Since(begin).String()), slog.Group( "page", - slog.Any("limit", pm.Limit), - slog.Any("offset", pm.Offset), + slog.Uint64("limit", pm.Limit), + slog.Uint64("offset", pm.Offset), + slog.Uint64("total", cp.Total), ), } if err != nil { @@ -150,7 +151,7 @@ func (lm *loggingMiddleware) UpdateClient(ctx context.Context, token string, cli defer func(begin time.Time) { args := []interface{}{ slog.String("duration", time.Since(begin).String()), - slog.Group("user", slog.String("name", c.Name), slog.String("id", c.ID)), slog.Any("metadata", c.Metadata), + slog.Group("user", slog.String("id", c.ID)), slog.String("name", c.Name), slog.Any("metadata", c.Metadata), } if err != nil { args = append(args, slog.Any("error", err)) @@ -168,7 +169,7 @@ func (lm *loggingMiddleware) UpdateClientTags(ctx context.Context, token string, defer func(begin time.Time) { args := []interface{}{ slog.String("duration", time.Since(begin).String()), - slog.Group("user", slog.String("id", c.ID), slog.String("tags", fmt.Sprintf("%v", c.Tags))), + slog.Group("user", slog.String("id", c.ID), slog.Any("tags", fmt.Sprintf("%v", c.Tags))), } if err != nil { args = append(args, slog.Any("error", err)) @@ -186,7 +187,7 @@ func (lm *loggingMiddleware) UpdateClientIdentity(ctx context.Context, token, id defer func(begin time.Time) { args := []interface{}{ slog.String("duration", time.Since(begin).String()), - slog.Group("user", slog.String("id", c.ID), slog.String("identity", identity)), + slog.Group("user", slog.String("id", c.ID)), } if err != nil { args = append(args, slog.Any("error", err)) @@ -222,6 +223,7 @@ func (lm *loggingMiddleware) GenerateResetToken(ctx context.Context, email, host defer func(begin time.Time) { args := []interface{}{ slog.String("duration", time.Since(begin).String()), + slog.String("host", host), } if err != nil { args = append(args, slog.Any("error", err)) @@ -327,12 +329,12 @@ func (lm *loggingMiddleware) ListMembers(ctx context.Context, token, objectKind, defer func(begin time.Time) { args := []interface{}{ slog.String("duration", time.Since(begin).String()), - slog.String("object_kind", objectKind), - slog.String("object_id", objectID), + slog.Group("object", slog.String("kind", objectKind), slog.String("id", objectID)), slog.Group( "page", slog.Any("limit", cp.Limit), - slog.Any("offset", cp.Offset), + slog.Uint64("offset", cp.Offset), + slog.Uint64("total", mp.Total), ), } if err != nil { diff --git a/ws/api/logging.go b/ws/api/logging.go index 49680d2f4..387798bff 100644 --- a/ws/api/logging.go +++ b/ws/api/logging.go @@ -29,12 +29,10 @@ func (lm *loggingMiddleware) Subscribe(ctx context.Context, thingKey, chanID, su defer func(begin time.Time) { args := []interface{}{ slog.String("duration", time.Since(begin).String()), - slog.String("thing_key", thingKey), slog.String("channel_id", chanID), } - destChannel := chanID if subtopic != "" { - args = append(args, "subtopic", subtopic, "channel", destChannel) + args = append(args, "subtopic", subtopic) } if err != nil { args = append(args, slog.Any("error", err))