This commit is contained in:
1 parent
dcd47bf6e7
commit
351defec7b
8 files changed
+362
-6
No files matched your search
@@ -11,6 +11,7 @@ import (
|
||||
"git.zhangdeman.cn/zhangdeman/ginframework/logger/storagevalue"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/ginframework/diagnostic"
|
||||
mysqlDriver "github.com/go-sql-driver/mysql"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
gormLogger "gorm.io/gorm/logger"
|
||||
@@ -110,6 +111,15 @@ func (l *Logger) Trace(ctx context.Context, begin time.Time, query func() (strin
|
||||
}
|
||||
fields = append(fields, storagevalue.Diagnostics(ctx)...)
|
||||
if err != nil {
|
||||
var (
|
||||
mysqlError *mysqlDriver.MySQLError
|
||||
)
|
||||
if errors.As(err, &mysqlError) {
|
||||
fields = append(fields, zap.Uint16("mysql_error_number", mysqlError.Number))
|
||||
if mysqlError.SQLState != [5]byte{} {
|
||||
fields = append(fields, zap.String("mysql_sql_state", string(mysqlError.SQLState[:])))
|
||||
}
|
||||
}
|
||||
l.instance.Error("SQL execution failed", fields...)
|
||||
return
|
||||
}
|
||||
|
||||