From cc112e72e4917152dd4c46a6b94b55b1c8b8dcc4 Mon Sep 17 00:00:00 2001 From: David Allen Date: Mon, 24 Mar 2025 14:43:34 -0600 Subject: [PATCH] refactor: changed logging to use consistent JSON format --- cmd/crawl.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cmd/crawl.go b/cmd/crawl.go index db9821c..9192d59 100644 --- a/cmd/crawl.go +++ b/cmd/crawl.go @@ -3,7 +3,8 @@ package cmd import ( "encoding/json" "fmt" - "log" + + "github.com/rs/zerolog/log" urlx "github.com/OpenCHAMI/magellan/internal/url" "github.com/OpenCHAMI/magellan/pkg/crawler" @@ -36,9 +37,11 @@ var CrawlCmd = &cobra.Command{ return nil }, Run: func(cmd *cobra.Command, args []string) { + // try and load credentials from local store first store, err := secrets.OpenStore(secretsFile) if err != nil { - fmt.Println(err) + log.Error().Err(err).Msg("failed to open store") + // try and use the `username` and `password` arguments instead store = &secrets.StaticStore{ Username: username, Password: password, @@ -47,15 +50,15 @@ var CrawlCmd = &cobra.Command{ systems, err := crawler.CrawlBMCForSystems(crawler.CrawlerConfig{ URI: args[0], CredentialStore: store, - Insecure: cmd.Flag("insecure").Value.String() == "true", + Insecure: insecure, }) if err != nil { - log.Fatalf("Error crawling BMC: %v", err) + log.Error().Err(err).Msg("error crawling BMC") } // Marshal the inventory details to JSON jsonData, err := json.MarshalIndent(systems, "", " ") if err != nil { - fmt.Println("Error marshalling to JSON:", err) + log.Error().Err(err).Msg("error marshalling to JSON:") return }