优化error的日志打印
This commit is contained in:
@@ -32,6 +32,12 @@ func (l *Logger) logger(ctx context.Context, event string, v ...any) {
|
|||||||
|
|
||||||
// writeStr := "[" + event + "]" + nowTime + " " + file + ":" + fmt.Sprintf("%d", line) + " " + funcName + " gid:" + getGID() + " " + traceId + " @data@: " + string(by) + "\n\n"
|
// writeStr := "[" + event + "]" + nowTime + " " + file + ":" + fmt.Sprintf("%d", line) + " " + funcName + " gid:" + getGID() + " " + traceId + " @data@: " + string(by) + "\n\n"
|
||||||
|
|
||||||
|
for idx,val := range v {
|
||||||
|
if _, ok := val.(error); ok {
|
||||||
|
v[idx] = fmt.Sprintf("%+v", val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fd := FormatData{
|
fd := FormatData{
|
||||||
Time: nowTime,
|
Time: nowTime,
|
||||||
File: file + ":" + fmt.Sprintf("%d", line),
|
File: file + ":" + fmt.Sprintf("%d", line),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package loggerx_test
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -38,6 +39,14 @@ func TestLogger(t *testing.T) {
|
|||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLogger2(t *testing.T) {
|
||||||
|
|
||||||
|
err := errors.New("test error")
|
||||||
|
loggerx.Info(context.Background(), err)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
type Print struct {
|
type Print struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user