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

Commit

Permalink
fix pages and log messages
Browse files Browse the repository at this point in the history
Signed-off-by: Musilah <[email protected]>
  • Loading branch information
Musilah committed Jan 24, 2024
1 parent a41127e commit 4c3e4d5
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 102 deletions.
4 changes: 2 additions & 2 deletions bootstrap/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 4 additions & 2 deletions certs/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions consumers/notifiers/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 17 additions & 14 deletions internal/groups/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down
40 changes: 20 additions & 20 deletions lora/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
46 changes: 20 additions & 26 deletions opcua/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Loading

0 comments on commit 4c3e4d5

Please sign in to comment.