From 1f4e8e5032c4cb751fd729452e817eb987d8d1c9 Mon Sep 17 00:00:00 2001 From: yinshuwei Date: Thu, 18 Jul 2024 15:54:44 +0800 Subject: [PATCH] logPrefix --- convert.go | 14 +++--- osm.go | 12 ++++- result_kvs.go | 4 +- result_strings.go | 4 +- result_struct.go | 4 +- result_structs.go | 4 +- result_value.go | 4 +- result_values.go | 4 +- sql.go | 122 +++++++++++++++++++++++++++++++++++----------- utils.go | 3 +- 10 files changed, 126 insertions(+), 49 deletions(-) diff --git a/convert.go b/convert.go index af6db7b..e9a032b 100644 --- a/convert.go +++ b/convert.go @@ -38,7 +38,7 @@ func setValueConvert(isPtr bool, dest reflect.Value, value interface{}, destType // convertAssign copies to dest the value in src, converting it if possible. // An error is returned if the copy would result in loss of information. // dest should be a pointer type. -func (o *osmBase) convertAssign(dest reflect.Value, src interface{}, destIsPtr bool, destType reflect.Type) error { +func (o *osmBase) convertAssign(logPrefix string, dest reflect.Value, src interface{}, destIsPtr bool, destType reflect.Type) error { switch s := src.(type) { case string: switch destType.Kind() { @@ -110,7 +110,7 @@ func (o *osmBase) convertAssign(dest reflect.Value, src interface{}, destIsPtr b case reflect.Bool: bv, err := driver.Bool.ConvertValue(src) if err != nil { - o.options.WarnLogger.Log("convertAssign Bool error", map[string]string{"error": err.Error()}) + o.options.WarnLogger.Log(logPrefix+"convertAssign Bool error", map[string]string{"error": err.Error()}) bv = false } setValue(destIsPtr, dest, bv.(bool), destType) @@ -120,7 +120,7 @@ func (o *osmBase) convertAssign(dest reflect.Value, src interface{}, destIsPtr b s = trimZeroDecimal(s) i64, err := strconv.ParseInt(s, 10, destType.Bits()) if err != nil { - o.options.WarnLogger.Log("convertAssign Int error", map[string]string{"error": err.Error()}) + o.options.WarnLogger.Log(logPrefix+"convertAssign Int error", map[string]string{"error": err.Error()}) } dest.SetInt(i64) return nil @@ -129,7 +129,7 @@ func (o *osmBase) convertAssign(dest reflect.Value, src interface{}, destIsPtr b s = trimZeroDecimal(s) u64, err := strconv.ParseUint(s, 10, destType.Bits()) if err != nil { - o.options.WarnLogger.Log("convertAssign Uint error", map[string]string{"error": err.Error()}) + o.options.WarnLogger.Log(logPrefix+"convertAssign Uint error", map[string]string{"error": err.Error()}) } dest.SetUint(u64) return nil @@ -137,7 +137,7 @@ func (o *osmBase) convertAssign(dest reflect.Value, src interface{}, destIsPtr b s := asString(src) f64, err := strconv.ParseFloat(s, destType.Bits()) if err != nil { - o.options.WarnLogger.Log("convertAssign Float error", map[string]string{"error": err.Error()}) + o.options.WarnLogger.Log(logPrefix+"convertAssign Float error", map[string]string{"error": err.Error()}) } dest.SetFloat(f64) return nil @@ -170,14 +170,14 @@ func (o *osmBase) convertAssign(dest reflect.Value, src interface{}, destIsPtr b t = t.Local() setValue(destIsPtr, dest, t, destType) } else { - o.options.WarnLogger.Log("convertAssign Time error", map[string]string{"error": err.Error()}) + o.options.WarnLogger.Log(logPrefix+"convertAssign Time error", map[string]string{"error": err.Error()}) } } return nil } } - o.options.WarnLogger.Log(fmt.Sprintf("unsupported Scan, storing driver.Value type %T into type %T", src, dest), nil) + o.options.WarnLogger.Log(logPrefix+fmt.Sprintf("unsupported Scan, storing driver.Value type %T into type %T", src, dest), nil) return nil } diff --git a/osm.go b/osm.go index ea0d7c9..9f05db4 100644 --- a/osm.go +++ b/osm.go @@ -5,7 +5,10 @@ package osm import ( "database/sql" "fmt" + "path" "reflect" + "runtime" + "strconv" "strings" "time" ) @@ -94,6 +97,13 @@ func (options *Options) tidy() { // SlowLogDuration: 500 * time.Millisecond, // time.Duration // }) func New(driverName, dataSource string, options Options) (*Osm, error) { + logPrefix := "" + _, file, lineNo, ok := runtime.Caller(1) + if ok { + fileName := path.Base(file) + logPrefix = fileName + ":" + strconv.Itoa(lineNo) + } + options.tidy() osm := &Osm{ osmBase: osmBase{ @@ -120,7 +130,7 @@ func New(driverName, dataSource string, options Options) (*Osm, error) { for { err := db.Ping() if err != nil { - osm.options.WarnLogger.Log("osm Ping fail", map[string]string{"error": err.Error()}) + osm.options.WarnLogger.Log(logPrefix+"osm Ping fail", map[string]string{"error": err.Error()}) } time.Sleep(time.Minute) } diff --git a/result_kvs.go b/result_kvs.go index 1dadfe4..b79dd2d 100644 --- a/result_kvs.go +++ b/result_kvs.go @@ -5,7 +5,7 @@ import ( "reflect" ) -func resultKvs(o *osmBase, id, sql string, sqlParams []interface{}, container interface{}) (int64, error) { +func resultKvs(logPrefix string, o *osmBase, id, sql string, sqlParams []interface{}, container interface{}) (int64, error) { pointValue := reflect.ValueOf(container) if pointValue.Kind() != reflect.Ptr { return 0, fmt.Errorf("sql '%s' error : kvs类型Query,查询结果类型应为map的指针,而您传入的并不是指针", id) @@ -40,7 +40,7 @@ func resultKvs(o *osmBase, id, sql string, sqlParams []interface{}, container in reflect.New(elementTypes[0]).Elem(), reflect.New(elementTypes[1]).Elem(), } - err = o.scanRow(rows, isPtrs, elementTypes, objs) + err = o.scanRow(logPrefix, rows, isPtrs, elementTypes, objs) if err != nil { return 0, fmt.Errorf("sql '%s' error : %s", id, err.Error()) } diff --git a/result_strings.go b/result_strings.go index 7ef4deb..3188ce9 100644 --- a/result_strings.go +++ b/result_strings.go @@ -47,7 +47,7 @@ func checkDatas(datas interface{}) *reflect.Value { } // resultStrings 数据库结果读入到columns,和datas。columns为[]string,datas为[][]string。 -func resultStrings(o *osmBase, id, sql string, sqlParams []interface{}, columnsContainer, datasContainer interface{}) (int64, error) { +func resultStrings(logPrefix string, o *osmBase, id, sql string, sqlParams []interface{}, columnsContainer, datasContainer interface{}) (int64, error) { columnsValue := checkColumns(columnsContainer) if columnsValue == nil { return 0, fmt.Errorf("sql '%s' error : strings类型Query,查询结果类型第一个为[]string的指针,第二个为[][]string的指针", id) @@ -84,7 +84,7 @@ func resultStrings(o *osmBase, id, sql string, sqlParams []interface{}, columnsC for i := 0; i < columnsCount; i++ { objs[i] = reflect.New(stringType).Elem() } - err = o.scanRow(rows, isPtrs, elementTypes, objs) + err = o.scanRow(logPrefix, rows, isPtrs, elementTypes, objs) if err != nil { return 0, fmt.Errorf("sql '%s' error : %s", id, err.Error()) } diff --git a/result_struct.go b/result_struct.go index 2c36008..0f88fe4 100644 --- a/result_struct.go +++ b/result_struct.go @@ -5,7 +5,7 @@ import ( "reflect" ) -func resultStruct(o *osmBase, id, sql string, sqlParams []interface{}, container interface{}) (int64, error) { +func resultStruct(logPrefix string, o *osmBase, id, sql string, sqlParams []interface{}, container interface{}) (int64, error) { pointValue := reflect.ValueOf(container) if pointValue.Kind() != reflect.Ptr { return 0, fmt.Errorf("sql '%s' error : struct类型Query,查询结果类型应为struct的指针,而您传入的并不是指针", id) @@ -52,7 +52,7 @@ func resultStruct(o *osmBase, id, sql string, sqlParams []interface{}, container values[i] = reflect.ValueOf(&a).Elem() } } - err = o.scanRow(rows, isPtrs, elementTypes, values) + err = o.scanRow(logPrefix, rows, isPtrs, elementTypes, values) if err != nil { return 0, fmt.Errorf("sql '%s' error : %s", id, err.Error()) } diff --git a/result_structs.go b/result_structs.go index ea91932..20d6202 100644 --- a/result_structs.go +++ b/result_structs.go @@ -6,7 +6,7 @@ import ( ) // resultStructs 数据库结果读入到struct切片中,struct可以是指针类型或非指针类型 -func resultStructs(o *osmBase, id, sql string, sqlParams []interface{}, container interface{}) (int64, error) { +func resultStructs(logPrefix string, o *osmBase, id, sql string, sqlParams []interface{}, container interface{}) (int64, error) { // 获得反射后结果的指针(这里应该是一个切片的指针) pointValue := reflect.ValueOf(container) if pointValue.Kind() != reflect.Ptr { @@ -87,7 +87,7 @@ func resultStructs(o *osmBase, id, sql string, sqlParams []interface{}, containe } } // 读取一行数据到成员实例切片中 - err = o.scanRow(rows, isPtrs, elementTypes, values) + err = o.scanRow(logPrefix, rows, isPtrs, elementTypes, values) if err != nil { return 0, fmt.Errorf("sql '%s' error : %s", id, err.Error()) } diff --git a/result_value.go b/result_value.go index d320f29..17d87b9 100644 --- a/result_value.go +++ b/result_value.go @@ -5,7 +5,7 @@ import ( "reflect" ) -func resultValue(o *osmBase, id, sql string, sqlParams []interface{}, containers []interface{}) (int64, error) { +func resultValue(logPrefix string, o *osmBase, id, sql string, sqlParams []interface{}, containers []interface{}) (int64, error) { lenContainers := len(containers) values := make([]reflect.Value, lenContainers) elementTypes := make([]reflect.Type, lenContainers) @@ -44,7 +44,7 @@ func resultValue(o *osmBase, id, sql string, sqlParams []interface{}, containers return 0, fmt.Errorf("sql '%s' error : value类型Query,查询结果的长度与SQL的长度不一致", id) } - err = o.scanRow(rows, isPtrs, elementTypes, values) + err = o.scanRow(logPrefix, rows, isPtrs, elementTypes, values) if err != nil { return 0, fmt.Errorf("sql '%s' error : %s", id, err.Error()) } diff --git a/result_values.go b/result_values.go index 405a7d0..e51e988 100644 --- a/result_values.go +++ b/result_values.go @@ -5,7 +5,7 @@ import ( "reflect" ) -func resultValues(o *osmBase, id, sql string, sqlParams []interface{}, containers []interface{}) (int64, error) { +func resultValues(logPrefix string, o *osmBase, id, sql string, sqlParams []interface{}, containers []interface{}) (int64, error) { lenContainers := len(containers) values := make([]reflect.Value, lenContainers) elementTypes := make([]reflect.Type, lenContainers) @@ -54,7 +54,7 @@ func resultValues(o *osmBase, id, sql string, sqlParams []interface{}, container for i := 0; i < lenContainers; i++ { objs[i] = reflect.New(elementTypes[i]).Elem() } - err = o.scanRow(rows, isPtrs, elementTypes, objs) + err = o.scanRow(logPrefix, rows, isPtrs, elementTypes, objs) if err != nil { return 0, fmt.Errorf("sql '%s' error : %s", id, err.Error()) } diff --git a/sql.go b/sql.go index f3a9c6c..5f0a329 100644 --- a/sql.go +++ b/sql.go @@ -4,7 +4,9 @@ import ( "encoding/json" "errors" "fmt" + "path" "reflect" + "runtime" "strconv" "strings" "time" @@ -35,14 +37,21 @@ const ( // // 删除id为1和2的用户数据 func (o *osmBase) Delete(sql string, params ...interface{}) (int64, error) { + logPrefix := "" + _, file, lineNo, ok := runtime.Caller(1) + if ok { + fileName := path.Base(file) + logPrefix = fileName + ":" + strconv.Itoa(lineNo) + } + now := time.Now() func(start time.Time) { if time.Since(start) > o.options.SlowLogDuration { - o.options.WarnLogger.Log("slow sql", map[string]string{"sql": sql, "cost": time.Since(start).String()}) + o.options.WarnLogger.Log(logPrefix+"slow sql", map[string]string{"sql": sql, "cost": time.Since(start).String()}) } }(now) - sql, sqlParams, err := o.readSQLParamsBySQL(sql, params...) + sql, sqlParams, err := o.readSQLParamsBySQL(logPrefix, sql, params...) if err != nil { return 0, err } @@ -74,14 +83,21 @@ func (o *osmBase) Delete(sql string, params ...interface{}) (int64, error) { // // 将id为1的用户email更新为"test2@foxmail.com" func (o *osmBase) Update(sql string, params ...interface{}) (int64, error) { + logPrefix := "" + _, file, lineNo, ok := runtime.Caller(1) + if ok { + fileName := path.Base(file) + logPrefix = fileName + ":" + strconv.Itoa(lineNo) + ", " + } + now := time.Now() func(start time.Time) { if time.Since(start) > o.options.SlowLogDuration { - o.options.WarnLogger.Log("slow sql", map[string]string{"sql": sql, "cost": time.Since(start).String()}) + o.options.WarnLogger.Log(logPrefix+"slow sql", map[string]string{"sql": sql, "cost": time.Since(start).String()}) } }(now) - sql, sqlParams, err := o.readSQLParamsBySQL(sql, params...) + sql, sqlParams, err := o.readSQLParamsBySQL(logPrefix, sql, params...) if err != nil { return 0, err } @@ -108,14 +124,21 @@ func (o *osmBase) Update(sql string, params ...interface{}) (int64, error) { // // 将id为3和4的用户email更新为"test@foxmail.com" func (o *osmBase) UpdateMulti(sql string, params ...interface{}) error { + logPrefix := "" + _, file, lineNo, ok := runtime.Caller(1) + if ok { + fileName := path.Base(file) + logPrefix = fileName + ":" + strconv.Itoa(lineNo) + ", " + } + now := time.Now() func(start time.Time) { if time.Since(start) > o.options.SlowLogDuration { - o.options.WarnLogger.Log("slow sql", map[string]string{"sql": sql, "cost": time.Since(start).String()}) + o.options.WarnLogger.Log(logPrefix+"slow sql", map[string]string{"sql": sql, "cost": time.Since(start).String()}) } }(now) - sql, sqlParams, err := o.readSQLParamsBySQL(sql, params...) + sql, sqlParams, err := o.readSQLParamsBySQL(logPrefix, sql, params...) if err != nil { return err } @@ -142,14 +165,21 @@ func (o *osmBase) UpdateMulti(sql string, params ...interface{}) error { // // 添加一个用户数据,email为"test@foxmail.com" func (o *osmBase) Insert(sql string, params ...interface{}) (int64, int64, error) { + logPrefix := "" + _, file, lineNo, ok := runtime.Caller(1) + if ok { + fileName := path.Base(file) + logPrefix = fileName + ":" + strconv.Itoa(lineNo) + ", " + } + now := time.Now() func(start time.Time) { if time.Since(start) > o.options.SlowLogDuration { - o.options.WarnLogger.Log("slow sql", map[string]string{"sql": sql, "cost": time.Since(start).String()}) + o.options.WarnLogger.Log(logPrefix+"slow sql", map[string]string{"sql": sql, "cost": time.Since(start).String()}) } }(now) - sql, sqlParams, err := o.readSQLParamsBySQL(sql, params...) + sql, sqlParams, err := o.readSQLParamsBySQL(logPrefix, sql, params...) if err != nil { return 0, 0, err } @@ -168,7 +198,7 @@ func (o *osmBase) Insert(sql string, params ...interface{}) (int64, int64, error if o.dbType == dbTypeMysql { insertID, err = result.LastInsertId() if err != nil { - o.options.ErrorLogger.Log("lastInsertId read error", map[string]string{"error": err.Error()}) + o.options.ErrorLogger.Log(logPrefix+"lastInsertId read error", map[string]string{"error": err.Error()}) } } @@ -193,7 +223,13 @@ func (o *osmBase) Insert(sql string, params ...interface{}) (int64, int64, error // // email: test@foxmail.com func (o *osmBase) SelectValue(sql string, params ...interface{}) func(containers ...interface{}) (int64, error) { - return o.selectBySQL(sql, resultTypeValue, params) + logPrefix := "" + _, file, lineNo, ok := runtime.Caller(1) + if ok { + fileName := path.Base(file) + logPrefix = fileName + ":" + strconv.Itoa(lineNo) + ", " + } + return o.selectBySQL(logPrefix, sql, resultTypeValue, params) } // SelectValues 执行查询sql @@ -213,7 +249,13 @@ func (o *osmBase) SelectValue(sql string, params ...interface{}) func(containers // // emails: [test@foxmail.com test@foxmail.com] func (o *osmBase) SelectValues(sql string, params ...interface{}) func(containers ...interface{}) (int64, error) { - return o.selectBySQL(sql, resultTypeValues, params) + logPrefix := "" + _, file, lineNo, ok := runtime.Caller(1) + if ok { + fileName := path.Base(file) + logPrefix = fileName + ":" + strconv.Itoa(lineNo) + ", " + } + return o.selectBySQL(logPrefix, sql, resultTypeValues, params) } // SelectStruct 执行查询sql @@ -233,7 +275,13 @@ func (o *osmBase) SelectValues(sql string, params ...interface{}) func(container // // user: ResUser{ID:1, Email:"test@foxmail.com", Mobile:"", Nickname:""} func (o *osmBase) SelectStruct(sql string, params ...interface{}) func(containers ...interface{}) (int64, error) { - return o.selectBySQL(sql, resultTypeStruct, params) + logPrefix := "" + _, file, lineNo, ok := runtime.Caller(1) + if ok { + fileName := path.Base(file) + logPrefix = fileName + ":" + strconv.Itoa(lineNo) + ", " + } + return o.selectBySQL(logPrefix, sql, resultTypeStruct, params) } // SelectStructs 执行查询sql @@ -253,7 +301,13 @@ func (o *osmBase) SelectStruct(sql string, params ...interface{}) func(container // // users: []ResUser{ResUser{ID:1, Email:"test@foxmail.com", Mobile:"", Nickname:""}} func (o *osmBase) SelectStructs(sql string, params ...interface{}) func(containers ...interface{}) (int64, error) { - return o.selectBySQL(sql, resultTypeStructs, params) + logPrefix := "" + _, file, lineNo, ok := runtime.Caller(1) + if ok { + fileName := path.Base(file) + logPrefix = fileName + ":" + strconv.Itoa(lineNo) + ", " + } + return o.selectBySQL(logPrefix, sql, resultTypeStructs, params) } // SelectKVS 执行查询sql @@ -273,7 +327,13 @@ func (o *osmBase) SelectStructs(sql string, params ...interface{}) func(containe // // idEmailMap: map[1:test@foxmail.com 2:test@foxmail.com] func (o *osmBase) SelectKVS(sql string, params ...interface{}) func(containers ...interface{}) (int64, error) { - return o.selectBySQL(sql, resultTypeKvs, params) + logPrefix := "" + _, file, lineNo, ok := runtime.Caller(1) + if ok { + fileName := path.Base(file) + logPrefix = fileName + ":" + strconv.Itoa(lineNo) + ", " + } + return o.selectBySQL(logPrefix, sql, resultTypeKvs, params) } // SelectStrings 执行查询sql @@ -295,18 +355,24 @@ func (o *osmBase) SelectKVS(sql string, params ...interface{}) func(containers . // columns: ["id", "email"] // datas: [["1",'test@foxmail.com'],["2","test@foxmail.com"]] func (o *osmBase) SelectStrings(sql string, params ...interface{}) func(containers ...interface{}) (int64, error) { - return o.selectBySQL(sql, resultTypeStrings, params) + logPrefix := "" + _, file, lineNo, ok := runtime.Caller(1) + if ok { + fileName := path.Base(file) + logPrefix = fileName + ":" + strconv.Itoa(lineNo) + ", " + } + return o.selectBySQL(logPrefix, sql, resultTypeStrings, params) } -func (o *osmBase) selectBySQL(sql, resultType string, params []interface{}) func(containers ...interface{}) (int64, error) { +func (o *osmBase) selectBySQL(logPrefix, sql, resultType string, params []interface{}) func(containers ...interface{}) (int64, error) { now := time.Now() func(start time.Time) { if time.Since(start) > o.options.SlowLogDuration { - o.options.WarnLogger.Log("slow sql", map[string]string{"sql": sql, "cost": time.Since(start).String()}) + o.options.WarnLogger.Log(logPrefix+"slow sql", map[string]string{"sql": sql, "cost": time.Since(start).String()}) } }(now) - sql, sqlParams, err := o.readSQLParamsBySQL(sql, params...) + sql, sqlParams, err := o.readSQLParamsBySQL(logPrefix, sql, params...) if err != nil { return func(containers ...interface{}) (int64, error) { @@ -318,32 +384,32 @@ func (o *osmBase) selectBySQL(sql, resultType string, params []interface{}) func switch resultType { case resultTypeStructs: if len(containers) == 1 { - return resultStructs(o, sql, sql, sqlParams, containers[0]) + return resultStructs(logPrefix, o, sql, sql, sqlParams, containers[0]) } err = fmt.Errorf("sql '%s' error : resultTypeStructs ,len(containers) != 1", sql) case resultTypeStruct: if len(containers) == 1 { - return resultStruct(o, sql, sql, sqlParams, containers[0]) + return resultStruct(logPrefix, o, sql, sql, sqlParams, containers[0]) } err = fmt.Errorf("sql '%s' error : resultTypeStruct ,len(containers) != 1", sql) case resultTypeValue: if len(containers) > 0 { - return resultValue(o, sql, sql, sqlParams, containers) + return resultValue(logPrefix, o, sql, sql, sqlParams, containers) } err = fmt.Errorf("sql '%s' error : resultTypeValue ,len(containers) < 1", sql) case resultTypeValues: if len(containers) > 0 { - return resultValues(o, sql, sql, sqlParams, containers) + return resultValues(logPrefix, o, sql, sql, sqlParams, containers) } err = fmt.Errorf("sql '%s' error : resultTypeValues ,len(containers) < 1", sql) case resultTypeKvs: if len(containers) == 1 { - return resultKvs(o, sql, sql, sqlParams, containers[0]) + return resultKvs(logPrefix, o, sql, sql, sqlParams, containers[0]) } err = fmt.Errorf("sql '%s' error : resultTypeKvs ,len(containers) != 1", sql) case resultTypeStrings: if len(containers) == 2 { - return resultStrings(o, sql, sql, sqlParams, containers[0], containers[1]) + return resultStrings(logPrefix, o, sql, sql, sqlParams, containers[0], containers[1]) } err = fmt.Errorf("sql '%s' error : resultTypeStrings ,len(containers) != 2", sql) } @@ -356,7 +422,7 @@ func (o *osmBase) selectBySQL(sql, resultType string, params []interface{}) func return callback } -func (o *osmBase) readSQLParamsBySQL(sqlOrg string, params ...interface{}) (sql string, sqlParams []interface{}, err error) { +func (o *osmBase) readSQLParamsBySQL(logPrefix string, sqlOrg string, params ...interface{}) (sql string, sqlParams []interface{}, err error) { var param interface{} paramsSize := len(params) if paramsSize > 0 { @@ -373,7 +439,7 @@ func (o *osmBase) readSQLParamsBySQL(sqlOrg string, params ...interface{}) (sql if o.options.ShowSQL { params, _ := json.Marshal(param) sqlParams, _ := json.Marshal(sqlParams) - o.options.InfoLogger.Log("readSQLParamsBySQL showSql", map[string]string{"sql": sqlOrg, "params": string(params), "dbSql": sql, "dbParams": string(sqlParams)}) + o.options.InfoLogger.Log(logPrefix+"readSQLParamsBySQL showSql", map[string]string{"sql": sqlOrg, "params": string(params), "dbSql": sql, "dbParams": string(sqlParams)}) } }() sqlTemp := sqlOrg @@ -399,7 +465,7 @@ func (o *osmBase) readSQLParamsBySQL(sqlOrg string, params ...interface{}) (sql sqlTemp = sqlTemp[ei+1:] errorIndex += ei + 1 } else { - o.options.ErrorLogger.Log("sql read error", map[string]string{"error": markSQLError(sqlOrg, errorIndex).Error()}) + o.options.ErrorLogger.Log(logPrefix+"sql read error", map[string]string{"error": markSQLError(sqlOrg, errorIndex).Error()}) return } } @@ -508,7 +574,7 @@ func (o *osmBase) readSQLParamsBySQL(sqlOrg string, params ...interface{}) (sql } else { sql = sqlOrg if o.options.ShowSQL { - o.options.InfoLogger.Log("readSQLParamsBySQL showSql", map[string]string{"sql": sql}) + o.options.InfoLogger.Log(logPrefix+"readSQLParamsBySQL showSql", map[string]string{"sql": sql}) } } return diff --git a/utils.go b/utils.go index 3549c10..56e705a 100644 --- a/utils.go +++ b/utils.go @@ -186,6 +186,7 @@ func findFiled(allFieldNameTypeMap map[string]*reflect.Type, name string) (strin // scanRow 从sql.Rows中读一行数据 func (o *osmBase) scanRow( + logPrefix string, rows *sql.Rows, isPtrs []bool, elementTypes []reflect.Type, @@ -214,7 +215,7 @@ func (o *osmBase) scanRow( if src == nil { continue } - o.convertAssign(values[i], *src, isPtrs[i], types[i]) + o.convertAssign(logPrefix, values[i], *src, isPtrs[i], types[i]) } return nil }