record not found back to the previous mode
This commit is contained in:
parent
d278ca49ef
commit
d4a1313643
@ -2,13 +2,11 @@ package gorm
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"gorm.io/gorm/logger"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrRecordNotFound record not found error
|
// ErrRecordNotFound record not found error
|
||||||
ErrRecordNotFound = logger.ErrRecordNotFound
|
ErrRecordNotFound = errors.New("record not found")
|
||||||
// ErrInvalidTransaction invalid transaction when you are trying to `Commit` or `Rollback`
|
// ErrInvalidTransaction invalid transaction when you are trying to `Commit` or `Rollback`
|
||||||
ErrInvalidTransaction = errors.New("no valid transaction")
|
ErrInvalidTransaction = errors.New("no valid transaction")
|
||||||
// ErrNotImplemented not implemented
|
// ErrNotImplemented not implemented
|
||||||
|
@ -9,11 +9,10 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
"gorm.io/gorm/utils"
|
"gorm.io/gorm/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrRecordNotFound = errors.New("record not found")
|
|
||||||
|
|
||||||
// Colors
|
// Colors
|
||||||
const (
|
const (
|
||||||
Reset = "\033[0m"
|
Reset = "\033[0m"
|
||||||
@ -142,7 +141,7 @@ func (l logger) Trace(ctx context.Context, begin time.Time, fc func() (string, i
|
|||||||
if l.LogLevel > Silent {
|
if l.LogLevel > Silent {
|
||||||
elapsed := time.Since(begin)
|
elapsed := time.Since(begin)
|
||||||
switch {
|
switch {
|
||||||
case err != nil && l.LogLevel >= Error && (!errors.Is(err, ErrRecordNotFound) || !l.IgnoreRecordNotFoundError):
|
case err != nil && l.LogLevel >= Error && (!errors.Is(err, gorm.ErrRecordNotFound) || !l.IgnoreRecordNotFoundError):
|
||||||
sql, rows := fc()
|
sql, rows := fc()
|
||||||
if rows == -1 {
|
if rows == -1 {
|
||||||
l.Printf(l.traceErrStr, utils.FileWithLineNum(), err, float64(elapsed.Nanoseconds())/1e6, "-", sql)
|
l.Printf(l.traceErrStr, utils.FileWithLineNum(), err, float64(elapsed.Nanoseconds())/1e6, "-", sql)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user