From bb43fb19d9a4b58ad3b94392033a37317fc6f5b1 Mon Sep 17 00:00:00 2001 From: LumenShip Date: Fri, 5 Jul 2024 11:17:51 +0800 Subject: [PATCH] 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. --- client/orm/orm_log.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/client/orm/orm_log.go b/client/orm/orm_log.go index da1e26cf..25145944 100644 --- a/client/orm/orm_log.go +++ b/client/orm/orm_log.go @@ -35,26 +35,32 @@ func NewLog(out io.Writer) *logs.Log { // LogFunc costomer log func 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{}) sub := time.Since(t) / 1e5 elsp := float64(int(sub)) / 10.0 logMap["cost_time"] = elsp - flag := " OK" + flag := "OK" if err != nil { flag = "FAIL" } + 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)) for _, arg := range args { cons = append(cons, fmt.Sprintf("%v", arg)) } if len(cons) > 0 { con += fmt.Sprintf(" - `%s`", strings.Join(cons, "`, `")) + logMap["cons"] = cons } if err != nil { con += " - " + err.Error() + logMap["err"] = err } logMap["sql"] = fmt.Sprintf("%s-`%s`", query, strings.Join(cons, "`, `")) if LogFunc != nil {