日志显示文件和行数
This commit is contained in:
parent
c09f54b9c0
commit
1f3ca99441
@ -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())
|
||||
}
|
||||
}
|
||||
|
@ -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...)
|
||||
|
Loading…
Reference in New Issue
Block a user