feat: add fields with logx methods, support using third party logging libs. (#1847)
* backup * simplify * chore: remove unused pool * chore: fix lint errors * chore: use strings.Builder instead of bytes.Buffer * test: add more tests * chore: fix reviewdog * test: fix data race * feat: make logger customizable * chore: fix reviewdog * test: fix fails * chore: fix set writer twice * chore: use context instead of golang.org context * chore: specify uint32 for level types
This commit is contained in:
36
core/logx/util.go
Normal file
36
core/logx/util.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package logx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/timex"
|
||||
)
|
||||
|
||||
func getCaller(callDepth int) string {
|
||||
_, file, line, ok := runtime.Caller(callDepth)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
|
||||
return prettyCaller(file, line)
|
||||
}
|
||||
|
||||
func getTimestamp() string {
|
||||
return timex.Time().Format(timeFormat)
|
||||
}
|
||||
|
||||
func prettyCaller(file string, line int) string {
|
||||
idx := strings.LastIndexByte(file, '/')
|
||||
if idx < 0 {
|
||||
return fmt.Sprintf("%s:%d", file, line)
|
||||
}
|
||||
|
||||
idx = strings.LastIndexByte(file[:idx], '/')
|
||||
if idx < 0 {
|
||||
return fmt.Sprintf("%s:%d", file, line)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s:%d", file[idx+1:], line)
|
||||
}
|
||||
Reference in New Issue
Block a user