Commit c85e7f9a authored by Matthew Sykes's avatar Matthew Sykes
Browse files

[FAB-12973] honor FABRIC_LOGGING_SPEC in library



When FABRIC_LOGGING_SPEC is set, the flogging library should use that
value to initialize the logging library. When it is not set, the default
logging spec of INFO should be used.

Change-Id: I9c3e70f96b7da229fde7074969112021376307c8
Signed-off-by: default avatarMatthew Sykes <sykesmat@us.ibm.com>
parent 9dea2247
......@@ -83,7 +83,10 @@ func (s *Logging) Apply(c Config) error {
}
if c.LogSpec == "" {
c.LogSpec = "INFO"
c.LogSpec = os.Getenv("FABRIC_LOGGING_SPEC")
}
if c.LogSpec == "" {
c.LogSpec = defaultLevel.String()
}
err = s.LoggerLevels.ActivateSpec(c.LogSpec)
......
......@@ -10,6 +10,7 @@ import (
"bytes"
"errors"
"fmt"
"os"
"testing"
"github.com/hyperledger/fabric/common/flogging"
......@@ -29,6 +30,23 @@ func TestNew(t *testing.T) {
assert.EqualError(t, err, "invalid logging specification '::=borken=::': bad segment '=borken='")
}
func TestNewWithEnvironment(t *testing.T) {
oldSpec, set := os.LookupEnv("FABRIC_LOGGING_SPEC")
if set {
defer os.Setenv("FABRIC_LOGGING_SPEC", oldSpec)
}
os.Setenv("FABRIC_LOGGING_SPEC", "fatal")
logging, err := flogging.New(flogging.Config{})
assert.NoError(t, err)
assert.Equal(t, zapcore.FatalLevel, logging.DefaultLevel())
os.Unsetenv("FABRIC_LOGGING_SPEC")
logging, err = flogging.New(flogging.Config{})
assert.NoError(t, err)
assert.Equal(t, zapcore.InfoLevel, logging.DefaultLevel())
}
//go:generate counterfeiter -o mock/write_syncer.go -fake-name WriteSyncer . writeSyncer
type writeSyncer interface {
zapcore.WriteSyncer
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment