Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
Signed-off-by: Musilah <[email protected]>
  • Loading branch information
Musilah committed Jan 22, 2024
1 parent ec0f256 commit 390958e
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 66 deletions.
5 changes: 3 additions & 2 deletions auth/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 4 additions & 7 deletions coap/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() != "" {
Expand All @@ -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))
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion consumers/notifiers/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
}
Expand Down
4 changes: 2 additions & 2 deletions internal/groups/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 2 additions & 6 deletions provision/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions readers/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
Expand Down
58 changes: 30 additions & 28 deletions things/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
6 changes: 3 additions & 3 deletions twins/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
),
}
Expand Down Expand Up @@ -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),
Expand Down
24 changes: 13 additions & 11 deletions users/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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 {
Expand All @@ -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))
Expand All @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 390958e

Please sign in to comment.