Skip to content

Commit b253e6d

Browse files
authored
add debug level switch (#175)
* add opt for debug swith * add opt for debug swith * update for pr
1 parent 928fe8b commit b253e6d

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

cmd/devstream/apply.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ DevStream will generate and execute a new plan based on the config file and the
2020

2121
func applyCMDFunc(cmd *cobra.Command, args []string) {
2222
log.Info("Apply started.")
23-
2423
if err := pluginengine.Apply(configFile, continueDirectly); err != nil {
2524
log.Errorf("Apply error: %s.", err)
2625
os.Exit(1)

cmd/devstream/main.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ package main
33
import (
44
"strings"
55

6-
"github.com/merico-dev/stream/internal/pkg/log"
7-
6+
"github.com/sirupsen/logrus"
87
"github.com/spf13/cobra"
98
"github.com/spf13/viper"
109

10+
"github.com/merico-dev/stream/internal/pkg/log"
1111
"github.com/merico-dev/stream/internal/pkg/pluginengine"
1212
)
1313

1414
var (
1515
configFile string
1616
pluginDir string
1717
continueDirectly bool
18+
isDebug bool
1819

1920
rootCMD = &cobra.Command{
2021
Use: "dtm",
@@ -29,6 +30,9 @@ var (
2930
# # # # # # # # # # # # # # #
3031
###### ###### ## ##### # # # ###### # # # #
3132
`,
33+
PersistentPreRun: func(cmd *cobra.Command, args []string) {
34+
initLog()
35+
},
3236
}
3337
)
3438

@@ -38,7 +42,7 @@ func init() {
3842
rootCMD.PersistentFlags().StringVarP(&configFile, "config-file", "f", "config.yaml", "config file")
3943
rootCMD.PersistentFlags().StringVarP(&pluginDir, "plugin-dir", "p", pluginengine.DefaultPluginDir, "plugins directory")
4044
rootCMD.PersistentFlags().BoolVarP(&continueDirectly, "yes", "y", false, "apply/delete directly without confirmation")
41-
45+
rootCMD.PersistentFlags().BoolVarP(&isDebug, "debug", "d", false, "debug level log")
4246
rootCMD.AddCommand(versionCMD)
4347
rootCMD.AddCommand(initCMD)
4448
rootCMD.AddCommand(applyCMD)
@@ -68,6 +72,15 @@ func initConfig() {
6872
}
6973
}
7074

75+
func initLog() {
76+
if isDebug {
77+
logrus.SetLevel(logrus.DebugLevel)
78+
} else {
79+
logrus.SetLevel(logrus.InfoLevel)
80+
}
81+
log.Info("Log level is: ", logrus.GetLevel())
82+
}
83+
7184
func main() {
7285
err := rootCMD.Execute()
7386
if err != nil {

0 commit comments

Comments
 (0)