package es import ( "context" "fmt" "gitea.drugeyes.vip/pharnexbase/utils/glog/v1" "strings" ) type Logger struct { } // 这里es打印日志时需要实现的方法 func (l *Logger) Printf(format string, v ...interface{}) { return } // 如果实现了此方法则不会调用上面的Printf func (l *Logger) PrintfWithContext(ctx context.Context, format string, v ...interface{}) { go func() { defer func() { if r := recover(); r != nil { fmt.Println("PrintfWithContext recover", r) } }() for _, item := range v { switch itemData := item.(type) { case string: itemData = strings.Replace(itemData, "\r\n", "", -1) glog.Glog.WithContext(ctx).Info(itemData) default: glog.Glog.WithContext(ctx).Infof(format, itemData) } } }() }