Update orm_log.go
Refactor debugLogQueries function in orm_log.go The debugLogQueries function in orm_log.go was modified to fix typos, streamline the formatting of log entries, and include additional data. Key changes include the addition of new entries to logMap, including "alias_name", "operation", "query", "cons", and "err". DebugLog also replaces logs.DebugLog to output the log entry.
This commit is contained in:
parent
84dcf68cb1
commit
bb43fb19d9
@ -35,26 +35,32 @@ func NewLog(out io.Writer) *logs.Log {
|
|||||||
// LogFunc costomer log func
|
// LogFunc costomer log func
|
||||||
var LogFunc func(query map[string]interface{})
|
var LogFunc func(query map[string]interface{})
|
||||||
|
|
||||||
func debugLogQueies(alias *alias, operaton, query string, t time.Time, err error, args ...interface{}) {
|
func debugLogQueies(alias *alias, operation, query string, t time.Time, err error, args ...interface{}) {
|
||||||
logMap := make(map[string]interface{})
|
logMap := make(map[string]interface{})
|
||||||
sub := time.Since(t) / 1e5
|
sub := time.Since(t) / 1e5
|
||||||
elsp := float64(int(sub)) / 10.0
|
elsp := float64(int(sub)) / 10.0
|
||||||
logMap["cost_time"] = elsp
|
logMap["cost_time"] = elsp
|
||||||
flag := " OK"
|
flag := "OK"
|
||||||
if err != nil {
|
if err != nil {
|
||||||
flag = "FAIL"
|
flag = "FAIL"
|
||||||
}
|
}
|
||||||
|
|
||||||
logMap["flag"] = flag
|
logMap["flag"] = flag
|
||||||
con := fmt.Sprintf(" -[Queries/%s] - [%s / %11s / %7.1fms] - [%s]", alias.Name, flag, operaton, elsp, query)
|
con := fmt.Sprintf(" -[Queries/%s] - [ %s / %11s / %7.1fms] - [%s]", alias.Name, flag, operation, elsp, query)
|
||||||
|
logMap["alias_name"] = alias.Name
|
||||||
|
logMap["operation"] = operation
|
||||||
|
logMap["query"] = query
|
||||||
cons := make([]string, 0, len(args))
|
cons := make([]string, 0, len(args))
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
cons = append(cons, fmt.Sprintf("%v", arg))
|
cons = append(cons, fmt.Sprintf("%v", arg))
|
||||||
}
|
}
|
||||||
if len(cons) > 0 {
|
if len(cons) > 0 {
|
||||||
con += fmt.Sprintf(" - `%s`", strings.Join(cons, "`, `"))
|
con += fmt.Sprintf(" - `%s`", strings.Join(cons, "`, `"))
|
||||||
|
logMap["cons"] = cons
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
con += " - " + err.Error()
|
con += " - " + err.Error()
|
||||||
|
logMap["err"] = err
|
||||||
}
|
}
|
||||||
logMap["sql"] = fmt.Sprintf("%s-`%s`", query, strings.Join(cons, "`, `"))
|
logMap["sql"] = fmt.Sprintf("%s-`%s`", query, strings.Join(cons, "`, `"))
|
||||||
if LogFunc != nil {
|
if LogFunc != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user