Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MG-2059 - Set correct log level depending on error #2196

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions auth/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (lm *loggingMiddleware) ListObjects(ctx context.Context, pr auth.PolicyReq,
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("List objects failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "List objects failed to complete successfully", args...)
return
}
lm.logger.Info("List objects completed successfully", args...)
Expand All @@ -56,7 +56,7 @@ func (lm *loggingMiddleware) ListAllObjects(ctx context.Context, pr auth.PolicyR
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("List all objects failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "List all objects failed to complete successfully", args...)
return
}
lm.logger.Info("List all objects completed successfully", args...)
Expand All @@ -72,7 +72,7 @@ func (lm *loggingMiddleware) CountObjects(ctx context.Context, pr auth.PolicyReq
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Count objects failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Count objects failed to complete successfully", args...)
return
}
lm.logger.Info("Count objects completed successfully", args...)
Expand All @@ -87,7 +87,7 @@ func (lm *loggingMiddleware) ListSubjects(ctx context.Context, pr auth.PolicyReq
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("List subjects failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "List subjects failed to complete successfully", args...)
return
}
lm.logger.Info("List subjects completed successfully", args...)
Expand All @@ -109,7 +109,7 @@ func (lm *loggingMiddleware) ListAllSubjects(ctx context.Context, pr auth.Policy
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("List all subjects failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "List all subjects failed to complete successfully", args...)
return
}
lm.logger.Info("List all subjects completed successfully", args...)
Expand All @@ -125,7 +125,7 @@ func (lm *loggingMiddleware) CountSubjects(ctx context.Context, pr auth.PolicyRe
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Count subjects failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Count subjects failed to complete successfully", args...)
return
}
lm.logger.Info("Count subjects completed successfully", args...)
Expand All @@ -147,7 +147,7 @@ func (lm *loggingMiddleware) ListPermissions(ctx context.Context, pr auth.Policy
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("List permissions failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "List permissions failed to complete successfully", args...)
return
}
lm.logger.Info("List permissions completed successfully", args...)
Expand All @@ -167,7 +167,7 @@ func (lm *loggingMiddleware) Issue(ctx context.Context, token string, key auth.K
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Issue key failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Issue key failed to complete successfully", args...)
return
}
lm.logger.Info("Issue key completed successfully", args...)
Expand All @@ -184,7 +184,7 @@ func (lm *loggingMiddleware) Revoke(ctx context.Context, token, id string) (err
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Revoke key failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Revoke key failed to complete successfully", args...)
return
}
lm.logger.Info("Revoke key completed successfully", args...)
Expand All @@ -201,7 +201,7 @@ func (lm *loggingMiddleware) RetrieveKey(ctx context.Context, token, id string)
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Retrieve key failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Retrieve key failed to complete successfully", args...)
return
}
lm.logger.Info("Retrieve key completed successfully", args...)
Expand All @@ -221,7 +221,7 @@ func (lm *loggingMiddleware) Identify(ctx context.Context, token string) (id aut
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Identify key failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Identify key failed to complete successfully", args...)
return
}
lm.logger.Info("Identify key completed successfully", args...)
Expand All @@ -247,7 +247,7 @@ func (lm *loggingMiddleware) Authorize(ctx context.Context, pr auth.PolicyReq) (
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Authorize failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Authorize failed to complete successfully", args...)
return
}
lm.logger.Info("Authorize completed successfully", args...)
Expand All @@ -269,7 +269,7 @@ func (lm *loggingMiddleware) AddPolicy(ctx context.Context, pr auth.PolicyReq) (
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Add policy failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Add policy failed to complete successfully", args...)
return
}
lm.logger.Info("Add policy completed successfully", args...)
Expand All @@ -284,7 +284,7 @@ func (lm *loggingMiddleware) AddPolicies(ctx context.Context, prs []auth.PolicyR
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn(fmt.Sprintf("Add %d policies failed to complete successfully", len(prs)), args...)
lm.logger.WarnContext(ctx, fmt.Sprintf("Add %d policies failed to complete successfully", len(prs)), args...)
return
}
lm.logger.Info(fmt.Sprintf("Add %d policies completed successfully", len(prs)), args...)
Expand All @@ -307,7 +307,7 @@ func (lm *loggingMiddleware) DeletePolicy(ctx context.Context, pr auth.PolicyReq
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Delete policy failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Delete policy failed to complete successfully", args...)
return
}
lm.logger.Info("Delete policy completed successfully", args...)
Expand All @@ -322,7 +322,7 @@ func (lm *loggingMiddleware) DeletePolicies(ctx context.Context, prs []auth.Poli
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn(fmt.Sprintf("Delete %d policies failed to complete successfully", len(prs)), args...)
lm.logger.WarnContext(ctx, fmt.Sprintf("Delete %d policies failed to complete successfully", len(prs)), args...)
return
}
lm.logger.Info(fmt.Sprintf("Delete %d policies completed successfully", len(prs)), args...)
Expand All @@ -341,7 +341,7 @@ func (lm *loggingMiddleware) CreateDomain(ctx context.Context, token string, d a
}
if err != nil {
args := append(args, slog.String("error", err.Error()))
lm.logger.Warn("Create domain failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Create domain failed to complete successfully", args...)
return
}
lm.logger.Info("Create domain completed successfully", args...)
Expand All @@ -357,7 +357,7 @@ func (lm *loggingMiddleware) RetrieveDomain(ctx context.Context, token, id strin
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Retrieve domain failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Retrieve domain failed to complete successfully", args...)
return
}
lm.logger.Info("Retrieve domain completed successfully", args...)
Expand All @@ -373,7 +373,7 @@ func (lm *loggingMiddleware) RetrieveDomainPermissions(ctx context.Context, toke
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Retrieve domain permissions failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Retrieve domain permissions failed to complete successfully", args...)
return
}
lm.logger.Info("Retrieve domain permissions completed successfully", args...)
Expand All @@ -392,7 +392,7 @@ func (lm *loggingMiddleware) UpdateDomain(ctx context.Context, token, id string,
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Update domain failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Update domain failed to complete successfully", args...)
return
}
lm.logger.Info("Update domain completed successfully", args...)
Expand All @@ -412,7 +412,7 @@ func (lm *loggingMiddleware) ChangeDomainStatus(ctx context.Context, token, id s
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Change domain status failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Change domain status failed to complete successfully", args...)
return
}
lm.logger.Info("Change domain status completed successfully", args...)
Expand All @@ -432,7 +432,7 @@ func (lm *loggingMiddleware) ListDomains(ctx context.Context, token string, page
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("List domains failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "List domains failed to complete successfully", args...)
return
}
lm.logger.Info("List domains completed successfully", args...)
Expand All @@ -450,7 +450,7 @@ func (lm *loggingMiddleware) AssignUsers(ctx context.Context, token, id string,
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Assign users to domain failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Assign users to domain failed to complete successfully", args...)
return
}
lm.logger.Info("Assign users to domain completed successfully", args...)
Expand All @@ -468,7 +468,7 @@ func (lm *loggingMiddleware) UnassignUsers(ctx context.Context, token, id string
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Unassign users to domain failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Unassign users to domain failed to complete successfully", args...)
return
}
lm.logger.Info("Unassign users to domain completed successfully", args...)
Expand All @@ -484,7 +484,7 @@ func (lm *loggingMiddleware) ListUserDomains(ctx context.Context, token, userID
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("List user domains failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "List user domains failed to complete successfully", args...)
return
}
lm.logger.Info("List user domains completed successfully", args...)
Expand Down
26 changes: 13 additions & 13 deletions bootstrap/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (lm *loggingMiddleware) Add(ctx context.Context, token string, cfg bootstra
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Add new bootstrap failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Add new bootstrap failed to complete successfully", args...)
return
}
lm.logger.Info("Add new bootstrap completed successfully", args...)
Expand All @@ -54,7 +54,7 @@ func (lm *loggingMiddleware) View(ctx context.Context, token, id string) (saved
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("View thing config failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "View thing config failed to complete successfully", args...)
return
}
lm.logger.Info("View thing config completed successfully", args...)
Expand All @@ -76,7 +76,7 @@ func (lm *loggingMiddleware) Update(ctx context.Context, token string, cfg boots
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Update bootstrap config failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Update bootstrap config failed to complete successfully", args...)
return
}
lm.logger.Info("Update bootstrap config completed successfully", args...)
Expand All @@ -95,7 +95,7 @@ func (lm *loggingMiddleware) UpdateCert(ctx context.Context, token, thingID, cli
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Update bootstrap config certificate failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Update bootstrap config certificate failed to complete successfully", args...)
return
}
lm.logger.Info("Update bootstrap config certificate completed successfully", args...)
Expand All @@ -115,7 +115,7 @@ func (lm *loggingMiddleware) UpdateConnections(ctx context.Context, token, id st
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Update config connections failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Update config connections failed to complete successfully", args...)
return
}
lm.logger.Info("Update config connections completed successfully", args...)
Expand All @@ -139,7 +139,7 @@ func (lm *loggingMiddleware) List(ctx context.Context, token string, filter boot
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("List configs failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "List configs failed to complete successfully", args...)
return
}
lm.logger.Info("List configs completed successfully", args...)
Expand All @@ -158,7 +158,7 @@ func (lm *loggingMiddleware) Remove(ctx context.Context, token, id string) (err
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Remove bootstrap config failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Remove bootstrap config failed to complete successfully", args...)
return
}
lm.logger.Info("Remove bootstrap config completed successfully", args...)
Expand All @@ -175,7 +175,7 @@ func (lm *loggingMiddleware) Bootstrap(ctx context.Context, externalKey, externa
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("View bootstrap config failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "View bootstrap config failed to complete successfully", args...)
return
}
lm.logger.Info("View bootstrap completed successfully", args...)
Expand All @@ -193,7 +193,7 @@ func (lm *loggingMiddleware) ChangeState(ctx context.Context, token, id string,
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Change thing state failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Change thing state failed to complete successfully", args...)
return
}
lm.logger.Info("Change thing state completed successfully", args...)
Expand All @@ -214,7 +214,7 @@ func (lm *loggingMiddleware) UpdateChannelHandler(ctx context.Context, channel b
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Update channel handler failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Update channel handler failed to complete successfully", args...)
return
}
lm.logger.Info("Update channel handler completed successfully", args...)
Expand All @@ -231,7 +231,7 @@ func (lm *loggingMiddleware) RemoveConfigHandler(ctx context.Context, id string)
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Remove config handler failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Remove config handler failed to complete successfully", args...)
return
}
lm.logger.Info("Remove config handler completed successfully", args...)
Expand All @@ -248,7 +248,7 @@ func (lm *loggingMiddleware) RemoveChannelHandler(ctx context.Context, id string
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Remove channel handler failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Remove channel handler failed to complete successfully", args...)
return
}
lm.logger.Info("Remove channel handler completed successfully", args...)
Expand All @@ -266,7 +266,7 @@ func (lm *loggingMiddleware) DisconnectThingHandler(ctx context.Context, channel
}
if err != nil {
args = append(args, slog.Any("error", err))
lm.logger.Warn("Disconnect thing handler failed to complete successfully", args...)
lm.logger.WarnContext(ctx, "Disconnect thing handler failed to complete successfully", args...)
return
}
lm.logger.Info("Disconnect thing handler completed successfully", args...)
Expand Down
Loading
Loading