mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-21 06:36:19 +00:00
new logging
This commit is contained in:
@@ -40,8 +40,8 @@ func initFiles(cmd *cobra.Command, args []string) {
|
||||
genDoc.SaveAs(genFile)
|
||||
}
|
||||
|
||||
log.Notice("Initialized tendermint", "genesis", config.GenesisFile(), "priv_validator", config.PrivValidatorFile())
|
||||
logger.Info("Initialized tendermint", "genesis", config.GenesisFile(), "priv_validator", config.PrivValidatorFile())
|
||||
} else {
|
||||
log.Notice("Already initialized", "priv_validator", config.PrivValidatorFile())
|
||||
logger.Info("Already initialized", "priv_validator", config.PrivValidatorFile())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/tendermint/log15"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
"github.com/tendermint/tmlibs/log"
|
||||
)
|
||||
|
||||
var resetAllCmd = &cobra.Command{
|
||||
@@ -29,34 +29,33 @@ func init() {
|
||||
// XXX: this is totally unsafe.
|
||||
// it's only suitable for testnets.
|
||||
func resetAll(cmd *cobra.Command, args []string) {
|
||||
ResetAll(config.DBDir(), config.PrivValidatorFile(), log)
|
||||
ResetAll(config.DBDir(), config.PrivValidatorFile(), logger)
|
||||
}
|
||||
|
||||
// XXX: this is totally unsafe.
|
||||
// it's only suitable for testnets.
|
||||
func resetPrivValidator(cmd *cobra.Command, args []string) {
|
||||
resetPrivValidatorLocal(config.PrivValidatorFile(), log)
|
||||
resetPrivValidatorLocal(config.PrivValidatorFile(), logger)
|
||||
}
|
||||
|
||||
// Exported so other CLI tools can use it
|
||||
func ResetAll(dbDir, privValFile string, l log15.Logger) {
|
||||
resetPrivValidatorLocal(privValFile, l)
|
||||
func ResetAll(dbDir, privValFile string, logger log.Logger) {
|
||||
resetPrivValidatorLocal(privValFile, logger)
|
||||
os.RemoveAll(dbDir)
|
||||
l.Notice("Removed all data", "dir", dbDir)
|
||||
logger.Info("Removed all data", "dir", dbDir)
|
||||
}
|
||||
|
||||
func resetPrivValidatorLocal(privValFile string, l log15.Logger) {
|
||||
|
||||
func resetPrivValidatorLocal(privValFile string, logger log.Logger) {
|
||||
// Get PrivValidator
|
||||
var privValidator *types.PrivValidator
|
||||
if _, err := os.Stat(privValFile); err == nil {
|
||||
privValidator = types.LoadPrivValidator(privValFile)
|
||||
privValidator.Reset()
|
||||
l.Notice("Reset PrivValidator", "file", privValFile)
|
||||
logger.Info("Reset PrivValidator", "file", privValFile)
|
||||
} else {
|
||||
privValidator = types.GenPrivValidator()
|
||||
privValidator.SetFile(privValFile)
|
||||
privValidator.Save()
|
||||
l.Notice("Generated PrivValidator", "file", privValFile)
|
||||
logger.Info("Generated PrivValidator", "file", privValFile)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
cfg "github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tmlibs/logger"
|
||||
"github.com/tendermint/tmlibs/log"
|
||||
)
|
||||
|
||||
var (
|
||||
config = cfg.DefaultConfig()
|
||||
log = logger.New("module", "main")
|
||||
logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "main")
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -24,7 +27,18 @@ var RootCmd = &cobra.Command{
|
||||
err := viper.Unmarshal(config)
|
||||
config.SetRoot(config.RootDir)
|
||||
cfg.EnsureRoot(config.RootDir)
|
||||
logger.SetLogLevel(config.LogLevel)
|
||||
var option log.Option
|
||||
switch config.LogLevel {
|
||||
case "info":
|
||||
option = log.AllowInfo()
|
||||
case "debug":
|
||||
option = log.AllowDebug()
|
||||
case "error":
|
||||
option = log.AllowError()
|
||||
default:
|
||||
return fmt.Errorf("Expected either \"info\", \"debug\" or \"error\" log level, given %v", config.LogLevel)
|
||||
}
|
||||
logger = log.NewFilter(logger, option)
|
||||
return err
|
||||
},
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func runNode(cmd *cobra.Command, args []string) error {
|
||||
// always available, remove.
|
||||
genDocFile := config.GenesisFile()
|
||||
if !cmn.FileExists(genDocFile) {
|
||||
log.Notice(cmn.Fmt("Waiting for genesis file %v...", genDocFile))
|
||||
logger.Info(cmn.Fmt("Waiting for genesis file %v...", genDocFile))
|
||||
for {
|
||||
time.Sleep(time.Second)
|
||||
if !cmn.FileExists(genDocFile) {
|
||||
@@ -80,11 +80,11 @@ func runNode(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
// Create & start node
|
||||
n := node.NewNodeDefault(config)
|
||||
n := node.NewNodeDefault(config, logger.With("module", "node"))
|
||||
if _, err := n.Start(); err != nil {
|
||||
return fmt.Errorf("Failed to start node: %v", err)
|
||||
} else {
|
||||
log.Notice("Started node", "nodeInfo", n.Switch().NodeInfo())
|
||||
logger.Info("Started node", "nodeInfo", n.Switch().NodeInfo())
|
||||
}
|
||||
|
||||
// Trap signal, run forever.
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
data "github.com/tendermint/go-wire/data"
|
||||
"github.com/tendermint/go-wire/data"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
@@ -20,7 +20,7 @@ func init() {
|
||||
}
|
||||
|
||||
func showValidator(cmd *cobra.Command, args []string) {
|
||||
privValidator := types.LoadOrGenPrivValidator(config.PrivValidatorFile())
|
||||
privValidator := types.LoadOrGenPrivValidator(config.PrivValidatorFile(), logger)
|
||||
pubKeyJSONBytes, _ := data.ToJSON(privValidator.PubKey)
|
||||
fmt.Println(string(pubKeyJSONBytes))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user