You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
779 B
37 lines
779 B
2 years ago
|
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)
|
||
|
}
|
||
|
}
|
||
|
}()
|
||
|
}
|