Add support for --log_level
This commit is contained in:
parent
c36352e4a5
commit
18d7b6426b
|
@ -3,9 +3,39 @@ package commands
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
|
"github.com/tendermint/tmlibs/cli"
|
||||||
|
tmflags "github.com/tendermint/tmlibs/cli/flags"
|
||||||
"github.com/tendermint/tmlibs/log"
|
"github.com/tendermint/tmlibs/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultLogLevel = "error"
|
||||||
|
FlagLogLevel = "log_level"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "main")
|
logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "main")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var RootCmd = &cobra.Command{
|
||||||
|
Use: "basecoin",
|
||||||
|
Short: "A cryptocurrency framework in Golang based on Tendermint-Core",
|
||||||
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||||
|
level := viper.GetString(FlagLogLevel)
|
||||||
|
logger, err = tmflags.ParseLogLevel(level, logger, defaultLogLevel)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if viper.GetBool(cli.TraceFlag) {
|
||||||
|
logger = log.NewTracingLogger(logger)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RootCmd.PersistentFlags().String(FlagLogLevel, defaultLogLevel, "Log level")
|
||||||
|
}
|
||||||
|
|
|
@ -12,11 +12,9 @@ import (
|
||||||
"github.com/tendermint/abci/server"
|
"github.com/tendermint/abci/server"
|
||||||
eyes "github.com/tendermint/merkleeyes/client"
|
eyes "github.com/tendermint/merkleeyes/client"
|
||||||
"github.com/tendermint/tmlibs/cli"
|
"github.com/tendermint/tmlibs/cli"
|
||||||
cliflags "github.com/tendermint/tmlibs/cli/flags"
|
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
|
|
||||||
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||||
"github.com/tendermint/tendermint/config"
|
|
||||||
"github.com/tendermint/tendermint/node"
|
"github.com/tendermint/tendermint/node"
|
||||||
"github.com/tendermint/tendermint/proxy"
|
"github.com/tendermint/tendermint/proxy"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
|
@ -127,14 +125,9 @@ func startTendermint(dir string, basecoinApp *app.Basecoin) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
tmLogger, err := cliflags.ParseLogLevel(cfg.LogLevel, logger, config.DefaultConfig().LogLevel)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create & start tendermint node
|
// Create & start tendermint node
|
||||||
privValidator := types.LoadOrGenPrivValidator(cfg.PrivValidatorFile(), tmLogger)
|
privValidator := types.LoadOrGenPrivValidator(cfg.PrivValidatorFile(), logger)
|
||||||
n := node.NewNode(cfg, privValidator, proxy.NewLocalClientCreator(basecoinApp), tmLogger.With("module", "node"))
|
n := node.NewNode(cfg, privValidator, proxy.NewLocalClientCreator(basecoinApp), logger.With("module", "node"))
|
||||||
|
|
||||||
_, err = n.Start()
|
_, err = n.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -3,19 +3,14 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
|
|
||||||
"github.com/tendermint/basecoin/cmd/basecoin/commands"
|
"github.com/tendermint/basecoin/cmd/basecoin/commands"
|
||||||
"github.com/tendermint/tmlibs/cli"
|
"github.com/tendermint/tmlibs/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var RootCmd = &cobra.Command{
|
rt := commands.RootCmd
|
||||||
Use: "basecoin",
|
|
||||||
Short: "A cryptocurrency framework in Golang based on Tendermint-Core",
|
|
||||||
}
|
|
||||||
|
|
||||||
RootCmd.AddCommand(
|
rt.AddCommand(
|
||||||
commands.InitCmd,
|
commands.InitCmd,
|
||||||
commands.StartCmd,
|
commands.StartCmd,
|
||||||
commands.RelayCmd,
|
commands.RelayCmd,
|
||||||
|
@ -23,7 +18,7 @@ func main() {
|
||||||
commands.VersionCmd,
|
commands.VersionCmd,
|
||||||
)
|
)
|
||||||
|
|
||||||
cmd := cli.PrepareMainCmd(RootCmd, "BC", os.ExpandEnv("$HOME/.basecoin"))
|
cmd := cli.PrepareMainCmd(rt, "BC", os.ExpandEnv("$HOME/.basecoin"))
|
||||||
if err := cmd.Execute(); err != nil {
|
if err := cmd.Execute(); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue