go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

logx setting from etc/*.yaml will not be working, if the logx.XX is used in init() or svc.NewServiceContext(c)

Open mervin0502 opened this issue 1 year ago • 0 comments

Describe the bug

The logx can be setup once (i.e. #2188). If the logx is used in some package init function or in the function svc.NewServiceContext(c), the logx mode would be the "console" defaultly. As a result, the logx setting from etc/*.yaml will not be working.

	var c config.Config
	conf.MustLoad(*configFile, &c)
	ctx := svc.NewServiceContext(c)
	svr := server.NewAppassetServer(ctx)
	s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
		apppb.RegisterAppassetServer(grpcServer, svr)

		if c.Mode == service.DevMode || c.Mode == service.TestMode {
			reflection.Register(grpcServer)
		}
	})
	defer s.Stop()

mervin0502 avatar Jul 27 '22 09:07 mervin0502