github.com/lingyao2333/mo-zero@v1.4.1/core/logx/util.go (about) 1 package logx 2 3 import ( 4 "fmt" 5 "runtime" 6 "strings" 7 "time" 8 ) 9 10 func getCaller(callDepth int) string { 11 _, file, line, ok := runtime.Caller(callDepth) 12 if !ok { 13 return "" 14 } 15 16 return prettyCaller(file, line) 17 } 18 19 func getTimestamp() string { 20 return time.Now().Format(timeFormat) 21 } 22 23 func prettyCaller(file string, line int) string { 24 idx := strings.LastIndexByte(file, '/') 25 if idx < 0 { 26 return fmt.Sprintf("%s:%d", file, line) 27 } 28 29 idx = strings.LastIndexByte(file[:idx], '/') 30 if idx < 0 { 31 return fmt.Sprintf("%s:%d", file, line) 32 } 33 34 return fmt.Sprintf("%s:%d", file[idx+1:], line) 35 }