diff --git a/internal/pkg/logs/log.go b/internal/pkg/logs/log.go index 697c7a2..5dfa925 100644 --- a/internal/pkg/logs/log.go +++ b/internal/pkg/logs/log.go @@ -1,26 +1,29 @@ package logs import ( + "fmt" "log" + "runtime" "strings" ) func ErrPrintln(err error, desc string, args ...any) { - s := strings.Builder{} - tmp := "%s err:[%s]" - if desc == "" { - tmp = "%s%s" + if err == nil { + return } - s.WriteString(tmp) - argss := []any{desc, err} + var pcs [1]uintptr + runtime.Callers(2, pcs[:]) + f := runtime.CallersFrames([]uintptr{pcs[0]}) + ff, _ := f.Next() + s := strings.Builder{} + _, _ = fmt.Fprintf(&s, "%s:%d %s err:[%s]", ff.File, ff.Line, desc, err) if len(args) > 0 { s.WriteString(" args:") for _, arg := range args { - s.WriteString("%v ") - argss = append(argss, arg) + _, _ = fmt.Fprintf(&s, "%v", arg) } } if err != nil { - log.Printf(s.String(), argss...) + log.Println(s.String()) } } diff --git a/model/query_test.go b/model/query_test.go index 756558e..e82238c 100644 --- a/model/query_test.go +++ b/model/query_test.go @@ -4,6 +4,7 @@ import ( "context" "database/sql" "fmt" + "github.com/fthvgb1/wp-go/safety" _ "github.com/go-sql-driver/mysql" "github.com/jmoiron/sqlx" "reflect" @@ -107,7 +108,7 @@ func init() { if err != nil { panic(err) } - glob = NewSqlxQuery(db, NewUniversalDb(func(ctx2 context.Context, a any, s string, a2 ...any) error { + glob = NewSqlxQuery(safety.NewVar(db), NewUniversalDb(func(ctx2 context.Context, a any, s string, a2 ...any) error { x := FormatSql(s, a2...) fmt.Println(x) return glob.Selects(ctx2, a, s, a2...)