@@ -11,6 +11,7 @@ import (
1111 "strings"
1212 "time"
1313
14+ "github.com/hashicorp/go-hclog"
1415 "github.com/hashicorp/go-version"
1516 "github.com/mitchellh/cli"
1617 "github.com/mitchellh/mapstructure"
@@ -42,6 +43,7 @@ type cmd struct {
4243 http * flags.HTTPFlags
4344 help string
4445 client * api.Client
46+ logger hclog.Logger
4547
4648 // flags
4749 meshGateway bool
@@ -65,6 +67,7 @@ type cmd struct {
6567 prometheusCertFile string
6668 prometheusKeyFile string
6769 ignoreEnvoyCompatibility bool
70+ enableLogging bool
6871
6972 // mesh gateway registration information
7073 register bool
@@ -221,6 +224,9 @@ func (c *cmd) init() {
221224 "flag to `false` to ensure compatibility with Envoy and prevent potential issues. " +
222225 "Default is `false`." )
223226
227+ c .flags .BoolVar (& c .enableLogging , "enable-config-gen-logging" , false ,
228+ "Output debug log messages during config generation" )
229+
224230 c .http = & flags.HTTPFlags {}
225231 flags .Merge (c .flags , c .http .ClientFlags ())
226232 flags .Merge (c .flags , c .http .MultiTenancyFlags ())
@@ -274,13 +280,21 @@ func (c *cmd) Run(args []string) int {
274280 return 1
275281 }
276282
283+ opts := hclog.LoggerOptions {Level : hclog .Off }
284+ if c .enableLogging {
285+ opts .Level = hclog .Debug
286+ }
287+ c .logger = hclog .New (& opts )
288+
277289 // Setup Consul client
278290 var err error
279291 c .client , err = c .http .APIClient ()
280292 if err != nil {
281293 c .UI .Error (fmt .Sprintf ("Error connecting to Consul agent: %s" , err ))
282294 return 1
283295 }
296+ c .logger .Debug ("Initialized API client" )
297+
284298 // TODO: refactor
285299 return c .run (c .flags .Args ())
286300}
@@ -350,6 +364,7 @@ func (c *cmd) run(args []string) int {
350364 c .proxyID = c .gatewaySvcName
351365
352366 }
367+ c .logger .Debug ("Set Proxy ID" , "proxy-id" , c .proxyID )
353368 }
354369 if c .proxyID == "" {
355370 c .UI .Error ("No proxy ID specified. One of -proxy-id, -sidecar-for, or -gateway is " +
@@ -443,6 +458,7 @@ func (c *cmd) run(args []string) int {
443458 c .UI .Error (fmt .Sprintf ("Error registering service %q: %s" , svc .Name , err ))
444459 return 1
445460 }
461+ c .logger .Debug ("Proxy registration complete" )
446462
447463 if ! c .bootstrap {
448464 // We need stdout to be reserved exclusively for the JSON blob, so
@@ -457,6 +473,7 @@ func (c *cmd) run(args []string) int {
457473 }
458474
459475 // Generate config
476+ c .logger .Debug ("Generating bootstrap config" )
460477 bootstrapJson , err := c .generateConfig ()
461478 if err != nil {
462479 c .UI .Error (err .Error ())
@@ -465,11 +482,13 @@ func (c *cmd) run(args []string) int {
465482
466483 if c .bootstrap {
467484 // Just output it and we are done
485+ c .logger .Debug ("Outputting bootstrap config" )
468486 c .UI .Output (string (bootstrapJson ))
469487 return 0
470488 }
471489
472490 // Find Envoy binary
491+ c .logger .Debug ("Finding envoy binary" )
473492 binary , err := c .findBinary ()
474493 if err != nil {
475494 c .UI .Error ("Couldn't find envoy binary: " + err .Error ())
@@ -497,6 +516,7 @@ func (c *cmd) run(args []string) int {
497516 }
498517 }
499518
519+ c .logger .Debug ("Executing envoy binary" )
500520 err = execEnvoy (binary , nil , args , bootstrapJson )
501521 if err == errUnsupportedOS {
502522 c .UI .Error ("Directly running Envoy is only supported on linux and macOS " +
@@ -618,6 +638,7 @@ func (c *cmd) generateConfig() ([]byte, error) {
618638 if err != nil {
619639 return nil , err
620640 }
641+ c .logger .Debug ("Generated template args" )
621642
622643 var bsCfg BootstrapConfig
623644
@@ -665,6 +686,7 @@ func (c *cmd) generateConfig() ([]byte, error) {
665686 datacenter = svcList .Node .Datacenter
666687 c .gatewayKind = svcList .Services [0 ].Kind
667688 }
689+ c .logger .Debug ("Fetched registration info" )
668690 if svcProxyConfig == nil {
669691 return nil , errors .New ("service is not a Connect proxy or gateway" )
670692 }
@@ -700,6 +722,7 @@ func (c *cmd) generateConfig() ([]byte, error) {
700722 if err := generateAccessLogs (c , args ); err != nil {
701723 return nil , err
702724 }
725+ c .logger .Debug ("Generated access logs" )
703726
704727 // Setup ready listener for ingress gateway to pass healthcheck
705728 if c .gatewayKind == api .ServiceKindIngressGateway {
0 commit comments