From 726163667963ceb8196fd08e305d1ac33c13839c Mon Sep 17 00:00:00 2001 From: Silas Davis <silas@monax.io> Date: Sun, 18 Feb 2018 14:10:33 +0000 Subject: [PATCH] Prevent inadvertently setting output from top-level sink (and so skipping filters) Signed-off-by: Silas Davis <silas@monax.io> --- cmd/burrow/main.go | 7 +++++++ logging/config/presets/instructions_test.go | 21 ++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/cmd/burrow/main.go b/cmd/burrow/main.go index 00cc8b0c..9f24df90 100644 --- a/cmd/burrow/main.go +++ b/cmd/burrow/main.go @@ -31,6 +31,9 @@ func main() { burrow.Action = func() { // We need to reflect on whether this obscures where values are coming from conf := config.DefaultBurrowConfig() + // We treat logging a little differently in that if anything is set for logging we will not + // set default outputs + conf.Logging = nil err := source.EachOf( burrowConfigProvider(*configOpt), source.FirstOf( @@ -38,6 +41,10 @@ func main() { // Try working directory genesisDocProvider(config.DefaultGenesisDocJSONFileName, true)), ).Apply(conf) + // If no logging config was provided use the default + if conf.Logging == nil { + conf.Logging = logging_config.DefaultNodeLoggingConfig() + } if err != nil { fatalf("could not obtain config: %v", err) } diff --git a/logging/config/presets/instructions_test.go b/logging/config/presets/instructions_test.go index 7252db28..4947182f 100644 --- a/logging/config/presets/instructions_test.go +++ b/logging/config/presets/instructions_test.go @@ -5,7 +5,6 @@ import ( "fmt" - "github.com/BurntSushi/toml" "github.com/hyperledger/burrow/logging/config" "github.com/hyperledger/burrow/logging/loggers" "github.com/hyperledger/burrow/logging/structure" @@ -25,17 +24,21 @@ func TestBuildSinkConfig(t *testing.T) { config.Sink().SetTransform(config.FilterTransform(config.NoFilterMode, structure.ChannelKey, types.InfoChannelName)).SetOutput(config.StdoutOutput()))) - fmt.Println(config.JSONString(expectedSink), "\n", config.JSONString(builtSink)) + //fmt.Println(config.JSONString(expectedSink), "\n", config.JSONString(builtSink)) assert.Equal(t, config.JSONString(expectedSink), config.JSONString(builtSink)) } func TestMinimalPreset(t *testing.T) { - builtSink, err := BuildSinkConfig(Minimal) + builtSink, err := BuildSinkConfig(Minimal, Stderr) require.NoError(t, err) - loggingConfig := &config.LoggingConfig{ - RootSink: builtSink, - } - loggingConfigOut := new(config.LoggingConfig) - toml.Decode(loggingConfig.TOMLString(), loggingConfigOut) - assert.Equal(t, loggingConfig.TOMLString(), loggingConfigOut.TOMLString()) + expectedSink := config.Sink(). + AddSinks(config.Sink().SetTransform(config.PruneTransform(structure.TraceKey, structure.RunId)). + AddSinks(config.Sink().SetTransform(config.FilterTransform(config.IncludeWhenAllMatch, + structure.ChannelKey, types.InfoChannelName)). + AddSinks(config.Sink().SetTransform(config.FilterTransform(config.ExcludeWhenAnyMatches, + structure.ComponentKey, "Tendermint", + "module", "p2p", + "module", "mempool")).SetOutput(config.StderrOutput())))) + //fmt.Println(config.TOMLString(expectedSink), "\n", config.TOMLString(builtSink)) + assert.Equal(t, config.TOMLString(expectedSink), config.TOMLString(builtSink)) } -- GitLab