Skip to content

Commit

Permalink
chore: improve log mod name
Browse files Browse the repository at this point in the history
  • Loading branch information
sysulq committed Oct 26, 2022
1 parent 4b199ff commit dad3909
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pkg/client/grpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func DefaultConfig() *Config {
dialOptions: []grpc.DialOption{
grpc.WithInsecure(),
},
logger: xlog.Jupiter(),
logger: xlog.Jupiter().Named(ecode.ModClientGrpc),
BalancerName: roundrobin.Name, // round robin by default
DialTimeout: cast.ToDuration("3s"),
ReadTimeout: cast.ToDuration("1s"),
Expand Down
5 changes: 3 additions & 2 deletions pkg/client/resty/resty.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/alibaba/sentinel-golang/core/base"
"github.com/douyu/jupiter/pkg/conf"
"github.com/douyu/jupiter/pkg/core/constant"
"github.com/douyu/jupiter/pkg/core/ecode"
"github.com/douyu/jupiter/pkg/core/metric"
"github.com/douyu/jupiter/pkg/core/sentinel"
"github.com/douyu/jupiter/pkg/core/xtrace"
Expand Down Expand Up @@ -110,7 +111,7 @@ func DefaultConfig() *Config {
Timeout: cast.ToDuration("3000ms"),
EnableAccessLog: false,
EnableSentinel: true,
logger: xlog.Jupiter().With(xlog.FieldMod("resty")),
logger: xlog.Jupiter().Named(ecode.ModeClientResty),
}
}

Expand Down Expand Up @@ -235,7 +236,7 @@ func (config *Config) Build() (*resty.Client, error) {
func (c *Config) MustBuild() *resty.Client {
cc, err := c.Build()
if err != nil {
xlog.Jupiter().Panic("resty build failed", zap.Error(err), zap.Any("config", c))
c.logger.Panic("resty build failed", zap.Error(err), zap.Any("config", c))
}

return cc
Expand Down
22 changes: 14 additions & 8 deletions pkg/client/rocketmq/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,24 @@ import (

"github.com/apache/rocketmq-client-go/v2/primitive"
"github.com/apache/rocketmq-client-go/v2/rlog"
"github.com/douyu/jupiter/pkg/conf"
"github.com/douyu/jupiter/pkg/core/ecode"
"github.com/douyu/jupiter/pkg/xlog"
"go.uber.org/zap"
)

func init() {
rlog.SetLogLevel("debug")
rlog.SetLogger(&mqLogger{xlog.Jupiter()})
conf.OnLoaded(func(c *conf.Configuration) {
logger := xlog.Jupiter().Named(ecode.ModeClientRocketMQ)

primitive.PanicHandler = func(i interface{}) {
stack := make([]byte, 1024)
length := runtime.Stack(stack, true)
fmt.Fprint(os.Stderr, "[rocketmq panic recovery]\n", string(stack[:length]))
xlog.Jupiter().Error("rocketmq panic recovery", zap.Any("error", i))
}
rlog.SetLogLevel("debug")
rlog.SetLogger(&mqLogger{logger.WithOptions(zap.AddCallerSkip(2))})

primitive.PanicHandler = func(i interface{}) {
stack := make([]byte, 1024)
length := runtime.Stack(stack, true)
fmt.Fprint(os.Stderr, "[rocketmq panic recovery]\n", string(stack[:length]))
logger.Error("rocketmq panic recovery", zap.Any("error", i))
}
})
}
21 changes: 19 additions & 2 deletions pkg/core/ecode/unified.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,33 @@ const (
ModApp = "app"
// ModProc ...
ModProc = "proc"

// ModGrpcServer ...
ModGrpcServer = "server.grpc"
// ModHTTPServer ...
ModEchoServer = "server.echo"

ModCacheFreecache = "cache.freecache"

// ModRegistryETCD ...
ModRegistryETCD = "registry.etcd"

// ModClientETCD ...
ModClientETCD = "client.etcd"
// ModClientGrpc ...
ModClientGrpc = "client.grpc"
// ModClientMySQL ...
ModClientMySQL = "client.mysql"
// ModeClientRocketMQ ...
ModeClientRocketMQ = "client.rocketmq"
// ModClientRedis ...
ModClientRedis = "client.redis"
// ModeClientResty ...
ModeClientResty = "client.resty"

// ModStoreMySQL ...
ModStoreMySQL = "store.mysql"
// ModClientMongo ...
ModClientMongo = "store.mongo"

// ModXcronETCD ...
ModXcronETCD = "xcron.etcd"
)
5 changes: 1 addition & 4 deletions pkg/server/xecho/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ import (
"go.uber.org/zap"
)

//ModName named a mod
const ModName = "server.echo"

//Config HTTP config
type Config struct {
Host string
Expand Down Expand Up @@ -56,7 +53,7 @@ func DefaultConfig() *Config {
Debug: false,
Deployment: constant.DefaultDeployment,
SlowQueryThresholdInMilli: 500, // 500ms
logger: xlog.Jupiter().With(xlog.FieldMod(ModName)),
logger: xlog.Jupiter().Named(ecode.ModEchoServer),
EnableTLS: false,
CertFile: "cert.pem",
PrivateFile: "private.pem",
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/xgrpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func DefaultConfig() *Config {
DisableTrace: false,
EnableTLS: false,
SlowQueryThresholdInMilli: 500,
logger: xlog.Jupiter().With(xlog.FieldMod("server.grpc")),
logger: xlog.Jupiter().Named(ecode.ModGrpcServer),
serverOptions: []grpc.ServerOption{},
streamInterceptors: []grpc.StreamServerInterceptor{},
unaryInterceptors: []grpc.UnaryServerInterceptor{},
Expand Down

0 comments on commit dad3909

Please sign in to comment.