otto 7 months ago
parent
commit
ad8ab83fd2
  1. 3
      go.mod
  2. 4
      log.go
  3. 20
      log_test.go
  4. 6
      logger.go

3
go.mod

@ -3,7 +3,7 @@ module git.gz.internal.jumaiyx.cn/pkg/log
go 1.20
require (
git.gz.internal.jumaiyx.cn/jm/jmproto v0.0.0-20231031073517-c103168beca6
git.gz.internal.jumaiyx.cn/pkg/config/v2 v2.0.0-20231031075731-1876cfdf1a96
github.com/go-kratos/kratos/v2 v2.7.1
github.com/golang/glog v1.1.2
golang.org/x/net v0.17.0
@ -12,6 +12,7 @@ require (
require (
github.com/go-playground/form/v4 v4.2.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/kr/text v0.2.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect

4
log.go

@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"git.gz.internal.jumaiyx.cn/jm/jmproto/conf"
cproto "git.gz.internal.jumaiyx.cn/pkg/config/v2/cproto"
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"
@ -81,7 +81,7 @@ type klogger struct {
debug bool
}
func NewKLogger(c *conf.Log) klog.Logger {
func NewKLogger(c *cproto.Log) klog.Logger {
switch c.Level {
case "":

20
log_test.go

@ -3,7 +3,7 @@ package log
import (
"context"
"errors"
"git.gz.internal.jumaiyx.cn/jm/jmproto/conf"
"git.gz.internal.jumaiyx.cn/pkg/config/v2/cproto"
"git.gz.internal.jumaiyx.cn/pkg/log/klog"
"testing"
"time"
@ -17,16 +17,16 @@ func TestNewKLogger(t *testing.T) {
ctx := context.Background()
//ctx = context.WithValue(ctx, "reqId", "dadadada")
l := NewLogger(&conf.Log{
l := NewLogger(&cproto.Log{
Level: LevelDebug,
Kafka: &conf.Kafka{
Addr: []string{"123.207.103.194:9094", "106.55.69.140:9094", "42.194.191.63:9094"},
//Addr: []string{"175.178.113.184:31090"},
Topic: "log-information-record-dev",
Group: "log-information-record-dev",
Username: "user",
Password: "Rkyf1Ue9jUI0",
},
//Kafka: &conf.Kafka{
// Addr: []string{"123.207.103.194:9094", "106.55.69.140:9094", "42.194.191.63:9094"},
// //Addr: []string{"175.178.113.184:31090"},
// Topic: "log-information-record-dev",
// Group: "log-information-record-dev",
// Username: "user",
// Password: "Rkyf1Ue9jUI0",
//},
})
//l := DefaultLogger()
l.WithContext(ctx)

6
logger.go

@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"git.gz.internal.jumaiyx.cn/jm/jmproto/conf"
"git.gz.internal.jumaiyx.cn/pkg/config/v2/cproto"
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"
@ -56,7 +56,7 @@ type Logger interface {
}
// NewLogger new a logger with writer.
func NewLogger(c *conf.Log, opts ...klog.Option) Logger {
func NewLogger(c *cproto.Log, opts ...klog.Option) Logger {
if c == nil {
return DefaultLogger()
}
@ -68,7 +68,7 @@ func NewLogger(c *conf.Log, opts ...klog.Option) Logger {
}
func DefaultLogger() Logger {
l := NewKLogger(&conf.Log{
l := NewKLogger(&cproto.Log{
Level: LevelDebug,
Debug: true,
})

Loading…
Cancel
Save