@@ -3,18 +3,19 @@ package main
33import (
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
1414var (
1515 configFile string
1616 pluginDir string
1717 continueDirectly bool
18+ isDebug bool
1819
1920 rootCMD = & cobra.Command {
2021 Use : "dtm" ,
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+
7184func main () {
7285 err := rootCMD .Execute ()
7386 if err != nil {
0 commit comments