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

View File

@ -12,6 +12,7 @@ import (
"sync" "sync"
"gorm.io/gorm/clause" "gorm.io/gorm/clause"
"gorm.io/gorm/logger"
"gorm.io/gorm/schema" "gorm.io/gorm/schema"
"gorm.io/gorm/utils" "gorm.io/gorm/utils"
) )
@ -189,7 +190,7 @@ func (stmt *Statement) AddVar(writer clause.Writer, vars ...interface{}) {
writer.WriteString("(NULL)") writer.WriteString("(NULL)")
} }
case *DB: 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.Statement.Vars = append(subdb.Statement.Vars, stmt.Vars...)
subdb.callbacks.Query().Execute(subdb) subdb.callbacks.Query().Execute(subdb)
writer.WriteString(subdb.Statement.SQL.String()) writer.WriteString(subdb.Statement.SQL.String())