1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-02-03 13:11:42 +02:00

fix log incorrect source when use pattern render

This commit is contained in:
wei cheng 2019-05-12 20:27:12 +08:00
parent 84c8ac1088
commit 493ea92280
No known key found for this signature in database
GPG Key ID: 5AF7E34E6A971D7F

View File

@ -4,8 +4,6 @@ import (
"bytes"
"fmt"
"io"
"path"
"runtime"
"strings"
"sync"
"time"
@ -27,8 +25,8 @@ var patternMap = map[string]func(map[string]interface{}) string{
"i": keyFactory(_instanceID),
"e": keyFactory(_deplyEnv),
"z": keyFactory(_zone),
"S": longSource,
"s": shortSource,
"S": keyFactory(_source),
"s": keyFactory(_source),
"M": message,
}
@ -116,20 +114,6 @@ func keyFactory(key string) func(map[string]interface{}) string {
}
}
func longSource(map[string]interface{}) string {
if _, file, lineNo, ok := runtime.Caller(6); ok {
return fmt.Sprintf("%s:%d", file, lineNo)
}
return "unknown:0"
}
func shortSource(map[string]interface{}) string {
if _, file, lineNo, ok := runtime.Caller(6); ok {
return fmt.Sprintf("%s:%d", path.Base(file), lineNo)
}
return "unknown:0"
}
func longTime(map[string]interface{}) string {
return time.Now().Format("15:04:05.000")
}