Should not diplay SubQuery SQL log, close #3437

This commit is contained in:
Jinzhu 2020-09-09 16:26:11 +08:00
parent 0b6ef3cb87
commit f6117b7f3d
2 changed files with 11 additions and 6 deletions

View File

@ -2,6 +2,7 @@ package logger
import (
"context"
"io/ioutil"
"log"
"os"
"time"
@ -54,11 +55,14 @@ type Interface interface {
Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
}
var Default = New(log.New(os.Stdout, "\r\n", log.LstdFlags), Config{
SlowThreshold: 100 * time.Millisecond,
LogLevel: Warn,
Colorful: true,
})
var (
Discard = New(log.New(ioutil.Discard, "", log.LstdFlags), Config{})
Default = New(log.New(os.Stdout, "\r\n", log.LstdFlags), Config{
SlowThreshold: 100 * time.Millisecond,
LogLevel: Warn,
Colorful: true,
})
)
func New(writer Writer, config Config) Interface {
var (

View File

@ -12,6 +12,7 @@ import (
"sync"
"gorm.io/gorm/clause"
"gorm.io/gorm/logger"
"gorm.io/gorm/schema"
"gorm.io/gorm/utils"
)
@ -189,7 +190,7 @@ func (stmt *Statement) AddVar(writer clause.Writer, vars ...interface{}) {
writer.WriteString("(NULL)")
}
case *DB:
subdb := v.Session(&Session{DryRun: true, WithConditions: true}).getInstance()
subdb := v.Session(&Session{Logger: logger.Discard, DryRun: true, WithConditions: true}).getInstance()
subdb.Statement.Vars = append(subdb.Statement.Vars, stmt.Vars...)
subdb.callbacks.Query().Execute(subdb)
writer.WriteString(subdb.Statement.SQL.String())