Skip to content
Snippets Groups Projects
Commit 07450ca3 authored by Casey Kuhlman's avatar Casey Kuhlman Committed by GitHub
Browse files

Merge pull request #637 from silasdavis/failsafe-log

Make sure we log somewhere if no config supplied
parents 4e7f45a7 93330c8e
No related branches found
No related tags found
No related merge requests found
......@@ -49,7 +49,7 @@ func ViperSubConfig(conf *viper.Viper, configSubtreePath string) (subConfig *vip
func ReadViperConfig(configBytes []byte) (*viper.Viper, error) {
buf := bytes.NewBuffer(configBytes)
conf := viper.New()
viper.SetConfigType("toml")
conf.SetConfigType("toml")
err := conf.ReadConfig(buf)
if err != nil {
return nil, err
......
......@@ -107,6 +107,9 @@ func LoadServerConfig(chainId string, rootConfig *viper.Viper) (*server.ServerCo
}
func LoadLoggingConfigFromDo(do *definitions.Do) (*lconfig.LoggingConfig, error) {
if !do.Config.IsSet("logging") {
return nil, nil
}
loggingConfigMap := do.Config.GetStringMap("logging")
return lconfig.LoggingConfigFromMap(loggingConfigMap)
}
......
package core
import (
"testing"
"github.com/hyperledger/burrow/config"
"github.com/hyperledger/burrow/definitions"
lconfig "github.com/hyperledger/burrow/logging/config"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
)
func TestLoadLoggingConfigFromDo(t *testing.T) {
do := new(definitions.Do)
do.Config = viper.New()
lc, err := LoadLoggingConfigFromDo(do)
assert.NoError(t, err)
assert.Nil(t, lc, "Should get nil logging config when [logging] not set")
cnf, err := config.ReadViperConfig(([]byte)(lconfig.DefaultNodeLoggingConfig().RootTOMLString()))
assert.NoError(t, err)
do.Config = cnf
lc, err = LoadLoggingConfigFromDo(do)
assert.NoError(t, err)
assert.EqualValues(t, lconfig.DefaultNodeLoggingConfig(), lc)
}
package lifecycle
import (
"runtime"
"os"
"testing"
"time"
"bufio"
"github.com/stretchr/testify/assert"
)
func TestNewStdErrLogger(t *testing.T) {
logger := NewStdErrLogger()
func TestNewLoggerFromLoggingConfig(t *testing.T) {
stderr := os.Stderr
defer func() {
os.Stderr = stderr
}()
r, w, err := os.Pipe()
assert.NoError(t, err, "Couldn't make fifo")
os.Stderr = w
logger, err := NewLoggerFromLoggingConfig(nil)
assert.NoError(t, err)
logger.Info("Quick", "Test")
time.Sleep(time.Second)
runtime.Gosched()
reader := bufio.NewReader(r)
assert.NoError(t, err)
line, _, err := reader.ReadLine()
assert.NoError(t, err)
// This test shouldn't really depend on colour codes, if you find yourself
// changing it then assert.NotEmpty() should do
assert.Contains(t, string(line), "\x1b[34mQuick\x1b[0m=Test")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment