otto 7 months ago
parent
commit
82a720a9a4
  1. 29
      go.mod
  2. 31
      log.go
  3. 15
      request/req_id.go

29
go.mod

@ -4,23 +4,36 @@ go 1.18
require (
git.gz.internal.jumaiyx.cn/jm/jmproto v0.0.0-20230529080853-2a6b5e10c676
git.gz.internal.jumaiyx.cn/pkg/kafka v0.0.0-20230601090129-8a43b71530cb
git.gz.internal.jumaiyx.cn/pkg/kafka v0.0.0-20231007064145-54d0118eedba
github.com/go-kratos/kratos/v2 v2.5.3
github.com/golang/glog v1.0.0
github.com/segmentio/kafka-go v0.4.38
golang.org/x/net v0.3.0
golang.org/x/net v0.15.0
)
require (
github.com/IBM/sarama v1.41.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/eapache/go-resiliency v1.4.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/go-playground/form/v4 v4.2.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/klauspost/compress v1.15.12 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
github.com/jcmturner/gofork v1.7.6 // indirect
github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
github.com/xdg/scram v1.0.5 // indirect
github.com/xdg/stringprep v1.0.3 // indirect
golang.org/x/crypto v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
github.com/pierrec/lz4/v4 v4.1.18 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37 // indirect
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect

31
log.go

@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"git.gz.internal.jumaiyx.cn/jm/jmproto/conf"
"git.gz.internal.jumaiyx.cn/pkg/kafka"
klog "git.gz.internal.jumaiyx.cn/pkg/log/klog"
"git.gz.internal.jumaiyx.cn/pkg/log/request"
"git.gz.internal.jumaiyx.cn/pkg/log/tracing"
@ -103,12 +102,12 @@ func NewKLogger(c *conf.Log) klog.Logger {
}
if !c.Debug {
topic := Topic(c.Kafka.Topic)
kl.pool = &sync.Pool{
New: func() interface{} {
return kafka.NewSender(c.Kafka, topic)
},
}
//topic := Topic(c.Kafka.Topic)
//kl.pool = &sync.Pool{
// New: func() interface{} {
// return consumer.Consumer()
// },
//}
}
return kl
@ -163,15 +162,15 @@ func (l *klogger) Log(level klog.Level, keyvals ...interface{}) error {
// 忽略debug的打印
if level.String() != LevelDebug && !l.debug {
go func() {
sender := l.pool.Get().(*kafka.Sender)
if sender != nil {
if err := sender.Pub(context.TODO(), LogKafkaKey, data); err != nil {
fmt.Printf("Kafka sender failed:%v", err)
}
}
return
}()
//go func() {
// sender := l.pool.Get().(*kafka.Sender)
// if sender != nil {
// if err := sender.Pub(context.TODO(), LogKafkaKey, data); err != nil {
// fmt.Printf("Kafka sender failed:%v", err)
// }
// }
// return
//}()
}
return nil
}

15
request/req_id.go

@ -40,20 +40,5 @@ func GetReqId(ctx context.Context) (context.Context, string) {
}
ctx, reqId = SetReqReturnId(ctx)
}
//if ctx == nil {
// return SetReqReturnId(context.TODO())
//}
//
//var reqId string
//if ctx.Value(ContextReqId) != nil {
// reqId = ctx.Value(ContextReqId).(string)
// return ctx, reqId
//}
//
//if md, ok := metadata.FromServerContext(ctx); ok {
// reqId = md.Get(ContextReqId)
// return ctx, reqId
//}
return ctx, reqId
}

Loading…
Cancel
Save