forked from mirror/gorm
Should not diplay SubQuery SQL log, close #3437
This commit is contained in:
parent
0b6ef3cb87
commit
f6117b7f3d
|
@ -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 (
|
||||||
|
Discard = New(log.New(ioutil.Discard, "", log.LstdFlags), Config{})
|
||||||
|
Default = New(log.New(os.Stdout, "\r\n", log.LstdFlags), Config{
|
||||||
SlowThreshold: 100 * time.Millisecond,
|
SlowThreshold: 100 * time.Millisecond,
|
||||||
LogLevel: Warn,
|
LogLevel: Warn,
|
||||||
Colorful: true,
|
Colorful: true,
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
|
||||||
func New(writer Writer, config Config) Interface {
|
func New(writer Writer, config Config) Interface {
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -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())
|
||||||
|
|
Loading…
Reference in New Issue