mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-11 00:40:00 +08:00
37 lines
628 B
Go
37 lines
628 B
Go
|
|
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)
|
||
|
|
}
|