mirror of https://github.com/chaos-mesh/chaosd.git
add config log-level (#14)
* add config log-level Signed-off-by: xiang <xiang13225080@163.com> * add value Signed-off-by: xiang <xiang13225080@163.com>
This commit is contained in:
parent
fdd2220aa3
commit
fa13339e97
|
@ -14,11 +14,15 @@
|
|||
package ctl
|
||||
|
||||
import (
|
||||
"github.com/pingcap/log"
|
||||
"github.com/spf13/cobra"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/chaos-mesh/chaosd/cmd/chaosd/ctl/command"
|
||||
)
|
||||
|
||||
var logLevel string
|
||||
|
||||
// CommandFlags are flags that used in all Commands
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "chaosd",
|
||||
|
@ -26,6 +30,9 @@ var rootCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
func init() {
|
||||
cobra.OnInitialize(setLogLevel)
|
||||
rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "", "", "the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'")
|
||||
|
||||
rootCmd.AddCommand(
|
||||
command.NewServerCommand(),
|
||||
command.NewAttackCommand(),
|
||||
|
@ -41,3 +48,13 @@ func Execute() {
|
|||
command.ExitWithError(command.ExitError, err)
|
||||
}
|
||||
}
|
||||
|
||||
func setLogLevel() {
|
||||
conf := &log.Config{Level: logLevel}
|
||||
lg, r, err := log.InitLogger(conf)
|
||||
if err != nil {
|
||||
log.Error("fail to init log", zap.Error(err))
|
||||
return
|
||||
}
|
||||
log.ReplaceGlobals(lg, r)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue