Skip to content

Commit

Permalink
🧹 fix serve logging
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev committed Sep 26, 2024
1 parent 3f1c248 commit 35f24fc
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion apps/cnspec/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
"github.com/spf13/viper"
"go.mondoo.com/cnquery/v11"
"go.mondoo.com/cnquery/v11/cli/config"
"go.mondoo.com/cnquery/v11/logger"

cli_errors "go.mondoo.com/cnquery/v11/cli/errors"
"go.mondoo.com/cnquery/v11/cli/execruntime"
"go.mondoo.com/cnquery/v11/cli/inventoryloader"
"go.mondoo.com/cnquery/v11/cli/prof"
"go.mondoo.com/cnquery/v11/logger"
"go.mondoo.com/cnquery/v11/providers"
"go.mondoo.com/cnquery/v11/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v11/providers-sdk/v1/upstream"
Expand Down Expand Up @@ -53,6 +53,19 @@ var serveCmd = &cobra.Command{
_ = viper.BindPFlag("inventory-file", cmd.Flags().Lookup("inventory-file"))
_ = viper.BindPFlag("inventory-template", cmd.Flags().Lookup("inventory-template"))
logger.StandardZerologLogger()
// environment variables always over-write custom flags
envLevel, ok := logger.GetEnvLogLevel()
if ok {
logger.Set(envLevel)
return
}

// retrieve log-level from flags
level := viper.GetString("log-level")
if v := viper.GetBool("verbose"); v {
level = "debug"
}
logger.Set(level)
},
RunE: func(cmd *cobra.Command, args []string) error {
prof.InitProfiler()
Expand Down

0 comments on commit 35f24fc

Please sign in to comment.