2022-09-27 07:35:34 +00:00
|
|
|
package logs
|
|
|
|
|
|
|
|
import (
|
2023-04-06 13:13:02 +00:00
|
|
|
"fmt"
|
2022-09-27 07:35:34 +00:00
|
|
|
"log"
|
2023-04-06 13:13:02 +00:00
|
|
|
"runtime"
|
2022-09-27 07:35:34 +00:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ErrPrintln(err error, desc string, args ...any) {
|
2023-04-06 13:13:02 +00:00
|
|
|
if err == nil {
|
|
|
|
return
|
2022-09-27 07:35:34 +00:00
|
|
|
}
|
2023-04-06 13:13:02 +00:00
|
|
|
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)
|
2022-09-27 07:35:34 +00:00
|
|
|
if len(args) > 0 {
|
|
|
|
s.WriteString(" args:")
|
|
|
|
for _, arg := range args {
|
2023-04-06 13:13:02 +00:00
|
|
|
_, _ = fmt.Fprintf(&s, "%v", arg)
|
2022-09-27 07:35:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if err != nil {
|
2023-04-06 13:13:02 +00:00
|
|
|
log.Println(s.String())
|
2022-09-27 07:35:34 +00:00
|
|
|
}
|
|
|
|
}
|