convert repeated error checks into single function in logger (#15387)

This commit is contained in:
jiuker
2022-07-26 08:53:03 +08:00
committed by GitHub
parent 426c902b87
commit 6b4f833a12
3 changed files with 11 additions and 34 deletions
+2 -22
View File
@@ -19,8 +19,6 @@ package logger
import (
"context"
"errors"
"net/http"
"sync"
"time"
)
@@ -98,34 +96,16 @@ var logOnce = newLogOnceType()
// id is a unique identifier for related log messages, refer to cmd/notification.go
// on how it is used.
func LogOnceIf(ctx context.Context, err error, id interface{}, errKind ...interface{}) {
if err == nil {
if logIgnoreError(err) {
return
}
if errors.Is(err, context.Canceled) {
return
}
if err.Error() == http.ErrServerClosed.Error() || err.Error() == "disk not found" {
return
}
logOnce.logOnceIf(ctx, err, id, errKind...)
}
// LogOnceConsoleIf - similar to LogOnceIf but exclusively only logs to console target.
func LogOnceConsoleIf(ctx context.Context, err error, id interface{}, errKind ...interface{}) {
if err == nil {
if logIgnoreError(err) {
return
}
if errors.Is(err, context.Canceled) {
return
}
if err.Error() == http.ErrServerClosed.Error() || err.Error() == "disk not found" {
return
}
logOnce.logOnceConsoleIf(ctx, err, id, errKind...)
}