wp-go/internal/pkg/logs/log.go

27 lines
420 B
Go
Raw Normal View History

2022-09-27 07:35:34 +00:00
package logs
import (
"log"
"strings"
)
func ErrPrintln(err error, desc string, args ...any) {
s := strings.Builder{}
tmp := "%s err:[%s]"
if desc == "" {
tmp = "%s%s"
}
s.WriteString(tmp)
argss := []any{desc, err}
if len(args) > 0 {
s.WriteString(" args:")
for _, arg := range args {
s.WriteString("%v ")
argss = append(argss, arg)
}
}
if err != nil {
log.Printf(s.String(), argss...)
}
}