初步完成&测试可用
This commit is contained in:
@@ -10,23 +10,33 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func (l *Logger) logger(ctx context.Context, action string, v ...any) {
|
||||
func (l *Logger) logger(ctx context.Context, event string, v ...any) {
|
||||
pc, file, line, _ := runtime.Caller(2)
|
||||
// fmt.Println("runtime.Caller", pc, file, line, ok)
|
||||
|
||||
basePath, _ := filepath.Abs("./")
|
||||
basePath = strings.ReplaceAll(basePath, "\\", "/")
|
||||
// fmt.Println("basePath", basePath)
|
||||
|
||||
file = strings.TrimPrefix(file, basePath)
|
||||
|
||||
funcName := runtime.FuncForPC(pc).Name()
|
||||
funcName = filepath.Ext(funcName)
|
||||
funcName = strings.TrimPrefix(funcName, ".")
|
||||
|
||||
by, _ := json.Marshal(v)
|
||||
|
||||
nowTime := time.Now().Local().Format("20060102 15:04:05.000000")
|
||||
nowTime := time.Now().Local().Format("2006-01-02 15:04:05.000000")
|
||||
|
||||
traceId, _ := ctx.Value("trace_id").(string)
|
||||
traceId, _ := ctx.Value(l.option.traceField).(string)
|
||||
|
||||
writeStr := "[" + action + "]" + 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"
|
||||
|
||||
l.Write([]byte(writeStr))
|
||||
l.write(event, []byte(writeStr))
|
||||
|
||||
if l.option.errorToInfo && event == "error" {
|
||||
l.write("info", []byte(writeStr))
|
||||
}
|
||||
|
||||
// log.Println("" + string(by))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user