Skip to content

Commit c05d204

Browse files
authored
chore: debug logging & env var for log level (#45)
1 parent bc9ab60 commit c05d204

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

cmd/ctrlc/root/root.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package root
22

33
import (
4+
"os"
5+
46
"github.com/MakeNowJust/heredoc/v2"
57

68
"github.com/charmbracelet/log"
@@ -43,7 +45,7 @@ func NewRootCmd() *cobra.Command {
4345
},
4446
}
4547

46-
cmd.PersistentFlags().StringVar(&logLevel, "log-level", "info", "Set the logging level (debug, info, warn, error)")
48+
cmd.PersistentFlags().StringVar(&logLevel, "log-level", defaultOrEnv("info", "CTRLC_LOG_LEVEL"), "Set the logging level (debug, info, warn, error)")
4749

4850
cmd.AddCommand(agent.NewAgentCmd())
4951
cmd.AddCommand(api.NewAPICmd())
@@ -56,3 +58,14 @@ func NewRootCmd() *cobra.Command {
5658

5759
return cmd
5860
}
61+
62+
func defaultOrEnv(defaultValue string, envVarName string) string {
63+
if envVarName == "" {
64+
return defaultValue
65+
}
66+
value, set := os.LookupEnv(envVarName)
67+
if !set {
68+
value = defaultValue
69+
}
70+
return value
71+
}

cmd/ctrlc/root/sync/aws/networks/networks.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ func processNetwork(
234234
consoleUrl := getVpcConsoleUrl(vpc, region)
235235
metadata["ctrlplane/links"] = fmt.Sprintf("{ \"AWS Console\": \"%s\" }", consoleUrl)
236236

237+
log.Debug("Processed Network", "region", region, "name", vpcName, "id", *vpc.VpcId, "subnetCount", len(subnets))
237238
return api.ResourceProviderResource{
238239
Version: "ctrlplane.dev/network/v1",
239240
Kind: "AmazonNetwork",

0 commit comments

Comments
 (0)