"github.com/spf13/cobra"
"github.com/bytom/node"
+ "strings"
)
var runNodeCmd = &cobra.Command{
runNodeCmd.Flags().Bool("web.closed", config.Web.Closed, "Lanch web browser or not")
runNodeCmd.Flags().String("chain_id", config.ChainID, "Select network type")
+ // log level
+ runNodeCmd.Flags().String("log_level", config.LogLevel, "Select log level(debug, info, warn, error or fatal")
+
// p2p flags
runNodeCmd.Flags().String("p2p.laddr", config.P2P.ListenAddress, "Node listen address. (0.0.0.0:0 means any interface, any port)")
runNodeCmd.Flags().String("p2p.seeds", config.P2P.Seeds, "Comma delimited host:port seed nodes")
RootCmd.AddCommand(runNodeCmd)
}
+func getLogLevel(level string) log.Level {
+ switch strings.ToLower(level) {
+ case "debug":
+ return log.DebugLevel
+ case "info":
+ return log.InfoLevel
+ case "warn":
+ return log.WarnLevel
+ case "error":
+ return log.ErrorLevel
+ case "fatal":
+ return log.FatalLevel
+ default:
+ return log.InfoLevel
+ }
+}
+
func runNode(cmd *cobra.Command, args []string) error {
+ // Set log level by config.LogLevel
+ log.SetLevel(getLogLevel(config.LogLevel))
+
// Create & start node
n := node.NewNode(config)
if _, err := n.Start(); err != nil {
// then add the hook to logrus and set the log level to DEBUG
if os.Getenv("BYTOM_DEBUG") != "" {
log.AddHook(ContextHook{})
- log.SetLevel(log.DebugLevel)
}
}
//The ID of the network to json
ChainID string `mapstructure:"chain_id"`
+ //log level to set
+ LogLevel string `mapstructure:"log_level"`
+
// A JSON file containing the private key to use as a validator in the consensus protocol
PrivateKey string `mapstructure:"private_key"`