frostfs-node/pkg/services/object/search/search.go
Aleksey Savchuk f0c43c8d80
[#1502] Use zap.Error for logging errors
Use `zap.Error` instead of `zap.String` for logging errors: change all expressions like
`zap.String("error", err.Error())` or `zap.String("err", err.Error())` to `zap.Error(err)`.
Leave similar expressions with other messages unchanged, for example,
`zap.String("last_error", lastErr.Error())` or `zap.String("reason", ctx.Err().Error())`.

This change was made by applying the following patch:
```diff
@@
var err expression
@@
-zap.String("error", err.Error())
+zap.Error(err)

@@
var err expression
@@
-zap.String("err", err.Error())
+zap.Error(err)
```

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
2024-12-16 11:13:42 +03:00

45 lines
899 B
Go

package searchsvc
import (
"context"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
"go.uber.org/zap"
)
// Search serves a request to select the objects.
func (s *Service) Search(ctx context.Context, prm Prm) error {
exec := &execCtx{
svc: s,
prm: prm,
}
exec.setLogger(s.log)
return exec.execute(ctx)
}
func (exec *execCtx) execute(ctx context.Context) error {
exec.log.Debug(ctx, logs.ServingRequest)
err := exec.executeLocal(ctx)
exec.logResult(ctx, err)
if exec.isLocal() {
exec.log.Debug(ctx, logs.SearchReturnResultDirectly)
return err
}
err = exec.executeOnContainer(ctx)
exec.logResult(ctx, err)
return err
}
func (exec *execCtx) logResult(ctx context.Context, err error) {
switch {
default:
exec.log.Debug(ctx, logs.OperationFinishedWithError, zap.Error(err))
case err == nil:
exec.log.Debug(ctx, logs.OperationFinishedSuccessfully)
}
}