Skip to content

Commit

Permalink
record not found with warn,not than error
Browse files Browse the repository at this point in the history
  • Loading branch information
xcdong committed Apr 11, 2023
1 parent 3d0824c commit 92de3af
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion common/database/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package database

import (
"context"
"errors"
"fmt"
"gorm.io/gorm"
"time"

"github.com/kingwel-xie/k2/core/logger"
Expand Down Expand Up @@ -43,7 +45,11 @@ func (l gormLogger) Trace(ctx context.Context, begin time.Time, fc func() (strin
switch {
case err != nil:
sql, rows := fc()
log.Errorf("SQL: %v, elapsed=%f, %s, rows=%d", err, float64(elapsed.Nanoseconds())/1e6, sql, rows)
if errors.Is(err, gorm.ErrRecordNotFound) {
log.Warnf("SQL: %v, elapsed=%f, %s, rows=%d", err, float64(elapsed.Nanoseconds())/1e6, sql, rows)
} else {
log.Errorf("SQL: %v, elapsed=%f, %s, rows=%d", err, float64(elapsed.Nanoseconds())/1e6, sql, rows)
}

case elapsed > l.SlowThreshold && l.SlowThreshold != 0:
sql, rows := fc()
Expand Down

0 comments on commit 92de3af

Please sign in to comment.