From 39d5ff9ccb04149dbeba1e61a65b7531c27c09fc Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Mon, 30 Mar 2015 21:53:22 -0700 Subject: [PATCH] Reset log after config changes. --- cmd/main.go | 3 +++ config/config.go | 4 +++- logger/log.go | 21 +++++++++++---------- rpc/test/test.go | 2 +- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 15244b4e8..bc4828245 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -6,6 +6,7 @@ import ( "github.com/tendermint/tendermint2/config" "github.com/tendermint/tendermint2/daemon" + "github.com/tendermint/tendermint2/logger" ) func main() { @@ -27,6 +28,7 @@ Commands: switch args[0] { case "daemon": config.ParseFlags(args[1:]) + logger.Reset() daemon.Daemon() case "gen_account": gen_account() @@ -34,6 +36,7 @@ Commands: gen_validator() case "gen_tx": config.ParseFlags(args[1:]) + logger.Reset() gen_tx() case "probe_upnp": probe_upnp() diff --git a/config/config.go b/config/config.go index 48973a162..e8ed21540 100644 --- a/config/config.go +++ b/config/config.go @@ -163,8 +163,9 @@ func ParseFlags(args []string) { flags.BoolVar(&printHelp, "help", false, "Print this help message.") flags.String("listen_addr", app.GetString("ListenAddr"), "Listen address. (0.0.0.0:0 means any interface, any port)") flags.String("seed_node", app.GetString("SeedNode"), "Address of seed node") - flags.Bool("fast_sync", app.GetBool("FastSync"), "Fast blockchain syncing") flags.String("rpc_http_listen_addr", app.GetString("RPC.HTTP.ListenAddr"), "RPC listen address. Port required") + flags.Bool("fast_sync", app.GetBool("FastSync"), "Fast blockchain syncing") + flags.String("log_stdout_level", app.GetString("Log.Stdout.Level"), "Stdout log level") flags.Parse(args) if printHelp { flags.PrintDefaults() @@ -176,6 +177,7 @@ func ParseFlags(args []string) { app.BindPFlag("SeedNode", flags.Lookup("seed_node")) app.BindPFlag("FastSync", flags.Lookup("fast_sync")) app.BindPFlag("RPC.HTTP.ListenAddr", flags.Lookup("rpc_http_listen_addr")) + app.BindPFlag("Log.Stdout.Level", flags.Lookup("log_stdout_level")) // Confused? //app.Debug() diff --git a/logger/log.go b/logger/log.go index ddc6a7799..d3521fb5e 100644 --- a/logger/log.go +++ b/logger/log.go @@ -11,19 +11,12 @@ import ( var rootHandler log15.Handler -func getLevel(lvlString string) log15.Lvl { - lvl, err := log15.LvlFromString(lvlString) - if err != nil { - Exit(Fmt("Invalid log level %v: %v", lvlString, err)) - } - return lvl -} - func init() { - InitLog() + Reset() } -func InitLog() { +// You might want to call this after resetting tendermint/config. +func Reset() { handlers := []log15.Handler{} // By default, there's a stdout terminal format handler. @@ -62,3 +55,11 @@ func RootHandler() log15.Handler { func New(ctx ...interface{}) log15.Logger { return log15.Root().New(ctx...) } + +func getLevel(lvlString string) log15.Lvl { + lvl, err := log15.LvlFromString(lvlString) + if err != nil { + Exit(Fmt("Invalid log level %v: %v", lvlString, err)) + } + return lvl +} diff --git a/rpc/test/test.go b/rpc/test/test.go index d65151d8e..e391fee77 100644 --- a/rpc/test/test.go +++ b/rpc/test/test.go @@ -60,7 +60,7 @@ func init() { app.Set("PrivValidatorFile", rootDir+"/priv_validator.json") app.Set("Log.Stdout.Level", "debug") config.SetApp(app) - logger.InitLog() + logger.Reset() // start a node ready := make(chan struct{}) go newNode(ready)