Skip to content

Commit 97215fa

Browse files
committed
[FAB-9131] wire zap based fabric logger
Replace go-logging with a zap based implementation. The implementation is mostly compatible with the legacy format but differs in a two key ways: 1. CRITICAL and NOTICE log levels no longer exist. Calls to Critical get mapped to error and NOTICE gets mapped to INFO. The methods associated with these levels will be removed in a future CR. 2. The log level constants are now sourced from the zap/zapcore packages. These values are incompatible wit the go-logging constants. Please be sure to use the appropriate constant when necessary. The existing go-logging package is still used by the chaincode shim to reduce the risk of negatively impacting legacy chaincode. Change-Id: Iaf5fac807244883a8285892ccd350c5256959782 Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent bb90ac4 commit 97215fa

File tree

95 files changed

+1812
-1168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1812
-1168
lines changed

bccsp/pkcs11/impl_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import (
4141
"github.com/hyperledger/fabric/bccsp/signer"
4242
"github.com/hyperledger/fabric/bccsp/sw"
4343
"github.com/hyperledger/fabric/bccsp/utils"
44-
"github.com/op/go-logging"
4544
"github.com/stretchr/testify/assert"
4645
"golang.org/x/crypto/sha3"
4746
)
@@ -59,9 +58,6 @@ type testConfig struct {
5958
}
6059

6160
func TestMain(m *testing.M) {
62-
// Activate DEBUG level to cover listAttrs function
63-
logging.SetLevel(logging.DEBUG, "bccsp_p11")
64-
6561
ks, err := sw.NewFileBasedKeyStore(nil, os.TempDir(), false)
6662
if err != nil {
6763
fmt.Printf("Failed initiliazing KeyStore [%s]", err)

bccsp/pkcs11/pkcs11.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"sync"
1818

1919
"github.com/miekg/pkcs11"
20-
"github.com/op/go-logging"
20+
"go.uber.org/zap/zapcore"
2121
)
2222

2323
func loadLib(lib, pin, label string) (*pkcs11.Ctx, uint, *pkcs11.SessionHandle, error) {
@@ -290,7 +290,7 @@ func (csp *impl) generateECKey(curve asn1.ObjectIdentifier, ephemeral bool) (ski
290290

291291
pubGoKey := &ecdsa.PublicKey{Curve: nistCurve, X: x, Y: y}
292292

293-
if logger.IsEnabledFor(logging.DEBUG) {
293+
if logger.IsEnabledFor(zapcore.DebugLevel) {
294294
listAttrs(p11lib, session, prv)
295295
listAttrs(p11lib, session, pub)
296296
}

common/capabilities/capabilities_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@ import (
1111

1212
cb "github.com/hyperledger/fabric/protos/common"
1313

14-
"github.com/op/go-logging"
1514
"github.com/stretchr/testify/assert"
1615
)
1716

18-
func init() {
19-
logging.SetLevel(logging.DEBUG, pkgLogID)
20-
}
21-
2217
func TestSatisfied(t *testing.T) {
2318
var capsMap map[string]*cb.Capability
2419
for _, provider := range []*registry{

common/cauthdsl/cauthdsl.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import (
1414
"github.com/hyperledger/fabric/msp"
1515
cb "github.com/hyperledger/fabric/protos/common"
1616
mb "github.com/hyperledger/fabric/protos/msp"
17-
18-
"github.com/op/go-logging"
17+
"go.uber.org/zap/zapcore"
1918
)
2019

2120
var cauthdslLogger = flogging.MustGetLogger("cauthdsl")
@@ -93,7 +92,7 @@ func compile(policy *cb.SignaturePolicy, identities []*mb.MSPPrincipal, deserial
9392
cauthdslLogger.Debugf("%p skipping identity %d because it has already been used", signedData, i)
9493
continue
9594
}
96-
if cauthdslLogger.IsEnabledFor(logging.DEBUG) {
95+
if cauthdslLogger.IsEnabledFor(zapcore.DebugLevel) {
9796
// Unlike most places, this is a huge print statement, and worth checking log level before create garbage
9897
cauthdslLogger.Debugf("%p processing identity %d with bytes of %x", signedData, i, sd.Identity)
9998
}

common/cauthdsl/cauthdsl_test.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,13 @@ import (
1414

1515
"github.com/golang/protobuf/proto"
1616
"github.com/hyperledger/fabric/common/flogging"
17+
"github.com/hyperledger/fabric/common/flogging/floggingtest"
1718
"github.com/hyperledger/fabric/msp"
1819
cb "github.com/hyperledger/fabric/protos/common"
1920
mb "github.com/hyperledger/fabric/protos/msp"
20-
logging "github.com/op/go-logging"
2121
"github.com/stretchr/testify/assert"
2222
)
2323

24-
func init() {
25-
logging.SetLevel(logging.DEBUG, "")
26-
}
27-
2824
var invalidSignature = []byte("badsigned")
2925

3026
type mockIdentity struct {
@@ -289,19 +285,17 @@ func TestDeserializeIdentityError(t *testing.T) {
289285
spe, err := compile(policy.Rule, policy.Identities, &mockDeserializer{fail: errors.New("myError")})
290286
assert.NoError(t, err)
291287

292-
// Let logger output to buf
293-
var buf bytes.Buffer
294-
backend := logging.NewLogBackend(&buf, "", 0)
295-
cauthdslLogger.SetBackend(logging.AddModuleLevel(backend))
296-
defer func() {
297-
flogging.Reset()
298-
}()
288+
logger, recorder := floggingtest.NewTestLogger(t)
289+
defer func(old *flogging.FabricLogger) {
290+
cauthdslLogger = old
291+
}(cauthdslLogger)
292+
cauthdslLogger = logger
299293

300294
// Call
301295
signedData, used := toSignedData([][]byte{nil}, [][]byte{nil}, [][]byte{nil})
302296
ret := spe(signedData, used)
303297

304298
// Check result (ret and log)
305299
assert.False(t, ret)
306-
assert.Contains(t, buf.String(), "Principal deserialization failure (myError) for identity ")
300+
assert.Contains(t, string(recorder.Buffer().Contents()), "Principal deserialization failure (myError) for identity")
307301
}

common/channelconfig/application_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,8 @@ import (
1515

1616
"github.com/golang/protobuf/proto"
1717
. "github.com/onsi/gomega"
18-
logging "github.com/op/go-logging"
1918
)
2019

21-
func init() {
22-
logging.SetLevel(logging.DEBUG, "")
23-
}
24-
2520
func TestApplicationInterface(t *testing.T) {
2621
_ = Application((*ApplicationConfig)(nil))
2722
}

common/channelconfig/applicationorg.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
cb "github.com/hyperledger/fabric/protos/common"
1313
pb "github.com/hyperledger/fabric/protos/peer"
1414

15-
logging "github.com/op/go-logging"
1615
"github.com/pkg/errors"
1716
)
1817

@@ -69,8 +68,6 @@ func (aog *ApplicationOrgConfig) AnchorPeers() []*pb.AnchorPeer {
6968
}
7069

7170
func (aoc *ApplicationOrgConfig) Validate() error {
72-
if logger.IsEnabledFor(logging.DEBUG) {
73-
logger.Debugf("Anchor peers for org %s are %v", aoc.name, aoc.protos.AnchorPeers)
74-
}
71+
logger.Debugf("Anchor peers for org %s are %v", aoc.name, aoc.protos.AnchorPeers)
7572
return aoc.OrganizationConfig.Validate()
7673
}

common/channelconfig/channel_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,9 @@ import (
1515
"github.com/hyperledger/fabric/common/util"
1616
cb "github.com/hyperledger/fabric/protos/common"
1717

18-
logging "github.com/op/go-logging"
1918
"github.com/stretchr/testify/assert"
2019
)
2120

22-
func init() {
23-
logging.SetLevel(logging.DEBUG, "")
24-
}
25-
2621
func TestInterface(t *testing.T) {
2722
_ = Channel(&ChannelConfig{})
2823
}

common/channelconfig/orderer_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@ import (
1111

1212
ab "github.com/hyperledger/fabric/protos/orderer"
1313

14-
logging "github.com/op/go-logging"
1514
"github.com/stretchr/testify/assert"
1615
)
1716

18-
func init() {
19-
logging.SetLevel(logging.DEBUG, "")
20-
}
21-
2217
func TestBatchSize(t *testing.T) {
2318
validMaxMessageCount := uint32(10)
2419
validAbsoluteMaxBytes := uint32(1000)

common/configtx/configmap_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@ import (
1111

1212
cb "github.com/hyperledger/fabric/protos/common"
1313

14-
logging "github.com/op/go-logging"
1514
"github.com/stretchr/testify/assert"
1615
)
1716

18-
func init() {
19-
logging.SetLevel(logging.DEBUG, "")
20-
}
21-
2217
func TestBadKey(t *testing.T) {
2318
assert.Error(t, addToMap(comparable{key: "[Label]", path: []string{}}, make(map[string]comparable)),
2419
"Should have errored on key with illegal characters")

0 commit comments

Comments
 (0)