Skip to content

Commit

Permalink
add debug level switch (devstream-io#175)
Browse files Browse the repository at this point in the history
* add opt for debug swith

* add opt for debug swith

* update for pr
  • Loading branch information
lfbdev authored Feb 8, 2022
1 parent 928fe8b commit b253e6d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
1 change: 0 additions & 1 deletion cmd/devstream/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ DevStream will generate and execute a new plan based on the config file and the

func applyCMDFunc(cmd *cobra.Command, args []string) {
log.Info("Apply started.")

if err := pluginengine.Apply(configFile, continueDirectly); err != nil {
log.Errorf("Apply error: %s.", err)
os.Exit(1)
Expand Down
19 changes: 16 additions & 3 deletions cmd/devstream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ package main
import (
"strings"

"github.com/merico-dev/stream/internal/pkg/log"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/merico-dev/stream/internal/pkg/log"
"github.com/merico-dev/stream/internal/pkg/pluginengine"
)

var (
configFile string
pluginDir string
continueDirectly bool
isDebug bool

rootCMD = &cobra.Command{
Use: "dtm",
Expand All @@ -29,6 +30,9 @@ var (
# # # # # # # # # # # # # # #
###### ###### ## ##### # # # ###### # # # #
`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
initLog()
},
}
)

Expand All @@ -38,7 +42,7 @@ func init() {
rootCMD.PersistentFlags().StringVarP(&configFile, "config-file", "f", "config.yaml", "config file")
rootCMD.PersistentFlags().StringVarP(&pluginDir, "plugin-dir", "p", pluginengine.DefaultPluginDir, "plugins directory")
rootCMD.PersistentFlags().BoolVarP(&continueDirectly, "yes", "y", false, "apply/delete directly without confirmation")

rootCMD.PersistentFlags().BoolVarP(&isDebug, "debug", "d", false, "debug level log")
rootCMD.AddCommand(versionCMD)
rootCMD.AddCommand(initCMD)
rootCMD.AddCommand(applyCMD)
Expand Down Expand Up @@ -68,6 +72,15 @@ func initConfig() {
}
}

func initLog() {
if isDebug {
logrus.SetLevel(logrus.DebugLevel)
} else {
logrus.SetLevel(logrus.InfoLevel)
}
log.Info("Log level is: ", logrus.GetLevel())
}

func main() {
err := rootCMD.Execute()
if err != nil {
Expand Down

0 comments on commit b253e6d

Please sign in to comment.