40 lines
791 B
Go
40 lines
791 B
Go
|
package log
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"gorm.io/gorm/logger"
|
||
|
"testing"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type goTest struct {
|
||
|
t *testing.T
|
||
|
}
|
||
|
|
||
|
func (g *goTest) LogMode(_ logger.LogLevel) logger.Interface {
|
||
|
return g
|
||
|
}
|
||
|
|
||
|
func (g *goTest) Info(_ context.Context, s string, i ...interface{}) {
|
||
|
g.t.Log("Info: ", s, i)
|
||
|
|
||
|
}
|
||
|
|
||
|
func (g *goTest) Warn(_ context.Context, s string, i ...interface{}) {
|
||
|
g.t.Log("Warn: ", s, i)
|
||
|
|
||
|
}
|
||
|
|
||
|
func (g *goTest) Error(_ context.Context, s string, i ...interface{}) {
|
||
|
g.t.Log("Error: ", s, i)
|
||
|
}
|
||
|
|
||
|
func (g *goTest) Trace(_ context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error) {
|
||
|
sql, affected := fc()
|
||
|
g.t.Log(time.Now().Sub(begin), "\tSQL:", sql, "\tAffected:", affected, "\tErr:", err)
|
||
|
}
|
||
|
|
||
|
func GoTest(t *testing.T) logger.Interface {
|
||
|
return &goTest{t: t}
|
||
|
}
|