From 9606a4c4bd1cc4483ace1e49d2539d37ae08671f Mon Sep 17 00:00:00 2001 From: Troy Ronda Date: Mon, 5 Mar 2018 16:31:44 -0500 Subject: [PATCH] [FAB-8667] Levels in logging pkg This change duplicates levels into the logging package, so that only one package needs to be imported to set levels. The decorator package is merged with loglevel into logging/metadata. The testutils package is removed (replaced with vendored assert). The options package is moved under common. Change-Id: Ic97de6921e7979e2197906ea813cfa009012c86a Signed-off-by: Troy Ronda --- .../fabric/sdkpatch/logbridge/logbridge.go | 5 +- .../dynamicselection/dynamicselection_test.go | 3 +- pkg/{ => common}/options/options.go | 0 pkg/core/config/config.go | 7 +- .../bccsp/pkcs11/cryptosuiteimpl_test.go | 6 +- .../bccsp/wrapper/cryptosuiteimpl_test.go | 84 ++++++------ pkg/core/cryptosuite/cryptosuite_test.go | 54 ++++---- pkg/fab/comm/connection.go | 2 +- pkg/fab/comm/connectionopts.go | 2 +- pkg/fab/events/client/client.go | 2 +- pkg/fab/events/client/client_test.go | 3 +- .../events/client/dispatcher/dispatcher.go | 2 +- pkg/fab/events/client/dispatcher/opts.go | 2 +- pkg/fab/events/client/opts.go | 2 +- .../deliverclient/connection/connection.go | 2 +- pkg/fab/events/deliverclient/deliverclient.go | 2 +- .../deliverclient/deliverclient_test.go | 2 +- .../deliverclient/dispatcher/dispatcher.go | 2 +- pkg/fab/events/deliverclient/opts.go | 2 +- .../eventhubclient/connection/connection.go | 2 +- .../eventhubclient/dispatcher/dispatcher.go | 2 +- .../events/eventhubclient/eventhubclient.go | 2 +- .../eventhubclient/eventhubclient_test.go | 2 +- pkg/fab/events/eventhubclient/opts.go | 2 +- .../events/service/dispatcher/dispatcher.go | 2 +- pkg/fab/events/service/dispatcher/opts.go | 2 +- pkg/fab/events/service/service.go | 2 +- pkg/fab/events/service/service_test.go | 2 +- pkg/logging/api/logger.go | 12 ++ pkg/logging/decorator/callerInfo_test.go | 44 ------- pkg/logging/logger.go | 42 ++++-- pkg/logging/logger_test.go | 124 +++++++++--------- pkg/logging/loglevel/level.go | 58 -------- pkg/logging/loglevel/level_test.go | 53 -------- .../{decorator => metadata}/callerInfo.go | 24 ++-- pkg/logging/metadata/callerInfo_test.go | 44 +++++++ pkg/logging/metadata/level.go | 40 ++++++ pkg/logging/metadata/level_test.go | 54 ++++++++ pkg/logging/{loglevel => metadata}/utils.go | 12 +- pkg/logging/modlog/modlog.go | 103 +++++++-------- pkg/logging/modlog/modlog_test.go | 95 +++++++------- pkg/logging/modlog/testVerifyUtils.go | 25 ++-- pkg/logging/testutils/testutils.go | 54 -------- .../fabric/patches/0001-logbridge.patch | 11 +- 44 files changed, 479 insertions(+), 518 deletions(-) rename pkg/{ => common}/options/options.go (100%) delete mode 100644 pkg/logging/decorator/callerInfo_test.go delete mode 100644 pkg/logging/loglevel/level.go delete mode 100644 pkg/logging/loglevel/level_test.go rename pkg/logging/{decorator => metadata}/callerInfo.go (67%) create mode 100644 pkg/logging/metadata/callerInfo_test.go create mode 100644 pkg/logging/metadata/level.go create mode 100644 pkg/logging/metadata/level_test.go rename pkg/logging/{loglevel => metadata}/utils.go (65%) delete mode 100644 pkg/logging/testutils/testutils.go diff --git a/internal/github.com/hyperledger/fabric/sdkpatch/logbridge/logbridge.go b/internal/github.com/hyperledger/fabric/sdkpatch/logbridge/logbridge.go index 629ec62a0f..fe0209aee2 100644 --- a/internal/github.com/hyperledger/fabric/sdkpatch/logbridge/logbridge.go +++ b/internal/github.com/hyperledger/fabric/sdkpatch/logbridge/logbridge.go @@ -12,12 +12,11 @@ package logbridge import ( "github.com/hyperledger/fabric-sdk-go/pkg/logging" - "github.com/hyperledger/fabric-sdk-go/pkg/logging/loglevel" ) // Log levels (from fabric-sdk-go/pkg/logging/level.go). const ( - CRITICAL loglevel.Level = iota + CRITICAL logging.Level = iota ERROR WARNING INFO @@ -51,6 +50,6 @@ func (l *Logger) Warning(args ...interface{}) { } // IsEnabledFor bridges calls to the Go SDK logger's IsEnabledFor. -func (l *Logger) IsEnabledFor(level loglevel.Level) bool { +func (l *Logger) IsEnabledFor(level logging.Level) bool { return logging.IsEnabledFor(l.module, level) } diff --git a/pkg/client/common/selection/dynamicselection/dynamicselection_test.go b/pkg/client/common/selection/dynamicselection/dynamicselection_test.go index 86e75f4627..4676e46275 100644 --- a/pkg/client/common/selection/dynamicselection/dynamicselection_test.go +++ b/pkg/client/common/selection/dynamicselection/dynamicselection_test.go @@ -19,7 +19,6 @@ import ( "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk" "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/factory/defsvc" "github.com/hyperledger/fabric-sdk-go/pkg/logging" - "github.com/hyperledger/fabric-sdk-go/pkg/logging/loglevel" "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/core/common/ccprovider" "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" ) @@ -168,7 +167,7 @@ func verify(t *testing.T, service fab.SelectionService, expectedPeerGroups []pgr // Set the log level to WARNING since the following spits out too much info in DEBUG module := "pg-resolver" level := logging.GetLevel(module) - logging.SetLevel(module, loglevel.WARNING) + logging.SetLevel(module, logging.WARNING) defer logging.SetLevel(module, level) for i := 0; i < len(expectedPeerGroups); i++ { diff --git a/pkg/options/options.go b/pkg/common/options/options.go similarity index 100% rename from pkg/options/options.go rename to pkg/common/options/options.go diff --git a/pkg/core/config/config.go b/pkg/core/config/config.go index e4758c7c11..d8ea1cdfd7 100644 --- a/pkg/core/config/config.go +++ b/pkg/core/config/config.go @@ -25,7 +25,6 @@ import ( "github.com/hyperledger/fabric-sdk-go/pkg/core/config/cryptoutil" "github.com/hyperledger/fabric-sdk-go/pkg/core/config/urlutil" "github.com/hyperledger/fabric-sdk-go/pkg/logging" - "github.com/hyperledger/fabric-sdk-go/pkg/logging/loglevel" "github.com/pkg/errors" cs "github.com/hyperledger/fabric-sdk-go/pkg/core/cryptosuite" @@ -213,7 +212,7 @@ func initConfig(c *Config) (*Config, error) { } for _, logModule := range logModules { - logger.Infof("config %s logging level is set to: %s", logModule, loglevel.ParseString(logging.GetLevel(logModule))) + logger.Infof("config %s logging level is set to: %s", logModule, logging.ParseString(logging.GetLevel(logModule))) } return c, nil } @@ -233,7 +232,7 @@ func getCertPool(myViper *viper.Viper) (*x509.CertPool, error) { // setLogLevel will set the log level of the client func setLogLevel(myViper *viper.Viper) { loggingLevelString := myViper.GetString("client.logging.level") - logLevel := loglevel.INFO + logLevel := logging.INFO if loggingLevelString != "" { const logModule = "fabsdk" // TODO: allow more flexability in setting levels for different modules logger.Debugf("%s logging level from the config: %v", logModule, loggingLevelString) @@ -244,7 +243,7 @@ func setLogLevel(myViper *viper.Viper) { } } - // TODO: allow seperate settings for each + // TODO: allow separate settings for each for _, logModule := range logModules { logging.SetLevel(logModule, logLevel) } diff --git a/pkg/core/cryptosuite/bccsp/pkcs11/cryptosuiteimpl_test.go b/pkg/core/cryptosuite/bccsp/pkcs11/cryptosuiteimpl_test.go index a43656e60a..08f4174902 100644 --- a/pkg/core/cryptosuite/bccsp/pkcs11/cryptosuiteimpl_test.go +++ b/pkg/core/cryptosuite/bccsp/pkcs11/cryptosuiteimpl_test.go @@ -13,6 +13,7 @@ import ( "testing" "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/bccsp" pkcsFactory "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/bccsp/factory/pkcs11" @@ -20,7 +21,6 @@ import ( "github.com/hyperledger/fabric-sdk-go/pkg/context/api/core" api "github.com/hyperledger/fabric-sdk-go/pkg/context/api/core" "github.com/hyperledger/fabric-sdk-go/pkg/context/api/core/mocks" - "github.com/hyperledger/fabric-sdk-go/pkg/logging/testutils" ) var configImpl api.Config @@ -91,8 +91,8 @@ func TestCryptoSuiteByConfigPKCS11Failure(t *testing.T) { //Get cryptosuite using config samplecryptoSuite, err := GetSuiteByConfig(mockConfig) - testutils.VerifyNotEmpty(t, err, "Supposed to get error on GetSuiteByConfig call : %s", err) - testutils.VerifyEmpty(t, samplecryptoSuite, "Not supposed to get valid cryptosuite") + assert.NotEmpty(t, err, "Supposed to get error on GetSuiteByConfig call : %s", err) + assert.Empty(t, samplecryptoSuite, "Not supposed to get valid cryptosuite") } func TestPKCS11CSPConfigWithValidOptions(t *testing.T) { diff --git a/pkg/core/cryptosuite/bccsp/wrapper/cryptosuiteimpl_test.go b/pkg/core/cryptosuite/bccsp/wrapper/cryptosuiteimpl_test.go index 6fd2b25d0c..3565a16624 100644 --- a/pkg/core/cryptosuite/bccsp/wrapper/cryptosuiteimpl_test.go +++ b/pkg/core/cryptosuite/bccsp/wrapper/cryptosuiteimpl_test.go @@ -17,7 +17,7 @@ import ( "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/bccsp" "github.com/hyperledger/fabric-sdk-go/pkg/context/api/core" "github.com/hyperledger/fabric-sdk-go/pkg/context/api/core/mocks" - "github.com/hyperledger/fabric-sdk-go/pkg/logging/testutils" + "github.com/stretchr/testify/assert" ) const ( @@ -58,12 +58,12 @@ func TestCryptoSuiteByConfig(t *testing.T) { //Get cryptosuite using config samplecryptoSuite, err := getSuiteByConfig(mockConfig) - testutils.VerifyEmpty(t, err, "Not supposed to get error on GetSuiteByConfig call : %s", err) - testutils.VerifyNotEmpty(t, samplecryptoSuite, "Supposed to get valid cryptosuite") + assert.Empty(t, err, "Not supposed to get error on GetSuiteByConfig call : %s", err) + assert.NotEmpty(t, samplecryptoSuite, "Supposed to get valid cryptosuite") hashbytes, err := samplecryptoSuite.Hash([]byte(hashMessage), &bccsp.SHAOpts{}) - testutils.VerifyEmpty(t, err, "Not supposed to get error on GetSuiteByConfig call : %s", err) - testutils.VerifyNotEmpty(t, hashbytes, "Supposed to get valid hash from sample cryptosuite") + assert.Empty(t, err, "Not supposed to get error on GetSuiteByConfig call : %s", err) + assert.NotEmpty(t, hashbytes, "Supposed to get valid hash from sample cryptosuite") } @@ -81,8 +81,8 @@ func TestCryptoSuiteByConfigFailures(t *testing.T) { //Get cryptosuite using config samplecryptoSuite, err := getSuiteByConfig(mockConfig) - testutils.VerifyNotEmpty(t, err, "Supposed to get error on GetSuiteByConfig call : %s", err) - testutils.VerifyEmpty(t, samplecryptoSuite, "Not supposed to get valid cryptosuite") + assert.NotEmpty(t, err, "Supposed to get error on GetSuiteByConfig call : %s", err) + assert.Empty(t, samplecryptoSuite, "Not supposed to get valid cryptosuite") if !strings.HasPrefix(err.Error(), "Failed initializing configuration") { t.Fatalf("Didn't get expected failure, got %s instead", err) @@ -150,80 +150,80 @@ func TestCreateInvalidSecurityProviderPanic(t *testing.T) { func verifyCryptoSuite(t *testing.T, samplecryptoSuite core.CryptoSuite) { //Test cryptosuite.Sign signedBytes, err := samplecryptoSuite.Sign(GetKey(getMockKey(signingKey)), nil, nil) - testutils.VerifyEmpty(t, err, "Not supposed to get any error for samplecryptoSuite.GetKey : %s", err) - testutils.VerifyTrue(t, string(signedBytes) == mockIdentifier+signedIdentifier, "Got unexpected result from samplecryptoSuite.Sign") + assert.Empty(t, err, "Not supposed to get any error for samplecryptoSuite.GetKey : %s", err) + assert.True(t, string(signedBytes) == mockIdentifier+signedIdentifier, "Got unexpected result from samplecryptoSuite.Sign") //Test cryptosuite.Hash hashBytes, err := samplecryptoSuite.Hash([]byte(hashMessage), &bccsp.SHAOpts{}) - testutils.VerifyEmpty(t, err, "Not supposed to get any error for samplecryptoSuite.GetKey") - testutils.VerifyTrue(t, string(hashBytes) == mockIdentifier+hashMessage, "Got unexpected result from samplecryptoSuite.Hash") + assert.Empty(t, err, "Not supposed to get any error for samplecryptoSuite.GetKey") + assert.True(t, string(hashBytes) == mockIdentifier+hashMessage, "Got unexpected result from samplecryptoSuite.Hash") //Test cryptosuite.GetKey key, err := samplecryptoSuite.GetKey([]byte(sampleKey)) - testutils.VerifyEmpty(t, err, "Not supposed to get any error for samplecryptoSuite.GetKey") - testutils.VerifyNotEmpty(t, key, "Not supposed to get empty key for samplecryptoSuite.GetKey") + assert.Empty(t, err, "Not supposed to get any error for samplecryptoSuite.GetKey") + assert.NotEmpty(t, key, "Not supposed to get empty key for samplecryptoSuite.GetKey") keyBytes, err := key.Bytes() - testutils.VerifyEmpty(t, err, "Not supposed to get any error for samplecryptoSuite.GetKey().GetBytes()") - testutils.VerifyTrue(t, string(keyBytes) == sampleKey+getKey, "Not supposed to get empty bytes for samplecryptoSuite.GetKey().GetBytes()") + assert.Empty(t, err, "Not supposed to get any error for samplecryptoSuite.GetKey().GetBytes()") + assert.True(t, string(keyBytes) == sampleKey+getKey, "Not supposed to get empty bytes for samplecryptoSuite.GetKey().GetBytes()") skiBytes := key.SKI() - testutils.VerifyTrue(t, string(skiBytes) == sampleKey+getKey, "Not supposed to get empty bytes for samplecryptoSuite.GetKey().GetSKI()") + assert.True(t, string(skiBytes) == sampleKey+getKey, "Not supposed to get empty bytes for samplecryptoSuite.GetKey().GetSKI()") - testutils.VerifyTrue(t, key.Private(), "Not supposed to get false for samplecryptoSuite.GetKey().Private()") - testutils.VerifyTrue(t, key.Symmetric(), "Not supposed to get false for samplecryptoSuite.GetKey().Symmetric()") + assert.True(t, key.Private(), "Not supposed to get false for samplecryptoSuite.GetKey().Private()") + assert.True(t, key.Symmetric(), "Not supposed to get false for samplecryptoSuite.GetKey().Symmetric()") publikey, err := key.PublicKey() - testutils.VerifyEmpty(t, err, "Not supposed to get any error for samplecryptoSuite.GetKey().PublicKey()") - testutils.VerifyNotEmpty(t, publikey, "Not supposed to get empty key for samplecryptoSuite.GetKey().PublicKey()") + assert.Empty(t, err, "Not supposed to get any error for samplecryptoSuite.GetKey().PublicKey()") + assert.NotEmpty(t, publikey, "Not supposed to get empty key for samplecryptoSuite.GetKey().PublicKey()") //Test cryptosuite.KeyImport key, err = samplecryptoSuite.KeyImport(nil, &bccsp.X509PublicKeyImportOpts{Temporary: true}) - testutils.VerifyEmpty(t, err, "Not supposed to get any error for samplecryptoSuite.KeyImport") - testutils.VerifyNotEmpty(t, key, "Not supposed to get empty key for samplecryptoSuite.KeyImport") + assert.Empty(t, err, "Not supposed to get any error for samplecryptoSuite.KeyImport") + assert.NotEmpty(t, key, "Not supposed to get empty key for samplecryptoSuite.KeyImport") keyBytes, err = key.Bytes() - testutils.VerifyEmpty(t, err, "Not supposed to get any error for samplecryptoSuite.KeyImport().GetBytes()") - testutils.VerifyTrue(t, string(keyBytes) == mockIdentifier+keyImport, "Unexpected bytes for samplecryptoSuite.KeyImport().GetBytes()") + assert.Empty(t, err, "Not supposed to get any error for samplecryptoSuite.KeyImport().GetBytes()") + assert.True(t, string(keyBytes) == mockIdentifier+keyImport, "Unexpected bytes for samplecryptoSuite.KeyImport().GetBytes()") skiBytes = key.SKI() - testutils.VerifyTrue(t, string(skiBytes) == mockIdentifier+keyImport, "Unexpected bytes for samplecryptoSuite.KeyImport().GetSKI()") + assert.True(t, string(skiBytes) == mockIdentifier+keyImport, "Unexpected bytes for samplecryptoSuite.KeyImport().GetSKI()") - testutils.VerifyTrue(t, key.Private(), "Not supposed to get false for samplecryptoSuite.KeyImport().Private()") - testutils.VerifyTrue(t, key.Symmetric(), "Not supposed to get false for samplecryptoSuite.KeyImport().Symmetric()") + assert.True(t, key.Private(), "Not supposed to get false for samplecryptoSuite.KeyImport().Private()") + assert.True(t, key.Symmetric(), "Not supposed to get false for samplecryptoSuite.KeyImport().Symmetric()") publikey, err = key.PublicKey() - testutils.VerifyEmpty(t, err, "Not supposed to get any error for samplecryptoSuite.KeyImport().PublicKey()") - testutils.VerifyNotEmpty(t, publikey, "Not supposed to get empty key for samplecryptoSuite.KeyImport().PublicKey()") + assert.Empty(t, err, "Not supposed to get any error for samplecryptoSuite.KeyImport().PublicKey()") + assert.NotEmpty(t, publikey, "Not supposed to get empty key for samplecryptoSuite.KeyImport().PublicKey()") //Test cryptosuite.KeyGen key, err = samplecryptoSuite.KeyGen(nil) - testutils.VerifyEmpty(t, err, "Not supposed to get any error for samplecryptoSuite.KeyGen") - testutils.VerifyNotEmpty(t, key, "Not supposed to get empty key for samplecryptoSuite.KeyGen") + assert.Empty(t, err, "Not supposed to get any error for samplecryptoSuite.KeyGen") + assert.NotEmpty(t, key, "Not supposed to get empty key for samplecryptoSuite.KeyGen") keyBytes, err = key.Bytes() - testutils.VerifyEmpty(t, err, "Not supposed to get any error for samplecryptoSuite.KeyGen().GetBytes()") - testutils.VerifyTrue(t, string(keyBytes) == mockIdentifier+keyGen, "Unexpected bytes for samplecryptoSuite.KeyGen().GetBytes()") + assert.Empty(t, err, "Not supposed to get any error for samplecryptoSuite.KeyGen().GetBytes()") + assert.True(t, string(keyBytes) == mockIdentifier+keyGen, "Unexpected bytes for samplecryptoSuite.KeyGen().GetBytes()") skiBytes = key.SKI() - testutils.VerifyTrue(t, string(skiBytes) == mockIdentifier+keyGen, "Unexpected bytes for samplecryptoSuite.KeyGen().GetSKI()") + assert.True(t, string(skiBytes) == mockIdentifier+keyGen, "Unexpected bytes for samplecryptoSuite.KeyGen().GetSKI()") - testutils.VerifyTrue(t, key.Private(), "Not supposed to get false for samplecryptoSuite.KeyGen().Private()") - testutils.VerifyTrue(t, key.Symmetric(), "Not supposed to get false for samplecryptoSuite.KeyGen().Symmetric()") + assert.True(t, key.Private(), "Not supposed to get false for samplecryptoSuite.KeyGen().Private()") + assert.True(t, key.Symmetric(), "Not supposed to get false for samplecryptoSuite.KeyGen().Symmetric()") publikey, err = key.PublicKey() - testutils.VerifyEmpty(t, err, "Not supposed to get any error for samplecryptoSuite.KeyGen().PublicKey()") - testutils.VerifyNotEmpty(t, publikey, "Not supposed to get empty key for samplecryptoSuite.KeyGen().PublicKey()") + assert.Empty(t, err, "Not supposed to get any error for samplecryptoSuite.KeyGen().PublicKey()") + assert.NotEmpty(t, publikey, "Not supposed to get empty key for samplecryptoSuite.KeyGen().PublicKey()") //Test cryptosuite.GetHash hash, err := samplecryptoSuite.GetHash(&bccsp.SHA256Opts{}) - testutils.VerifyNotEmpty(t, err, "Supposed to get error for samplecryptoSuite.GetHash") - testutils.VerifyEmpty(t, hash, "Supposed to get empty hash for samplecryptoSuite.GetHash") + assert.NotEmpty(t, err, "Supposed to get error for samplecryptoSuite.GetHash") + assert.Empty(t, hash, "Supposed to get empty hash for samplecryptoSuite.GetHash") //Test cryptosuite.GetHash valid, err := samplecryptoSuite.Verify(GetKey(getMockKey(signingKey)), nil, nil, nil) - testutils.VerifyEmpty(t, err, "Not supposed to get error for samplecryptoSuite.Verify") - testutils.VerifyTrue(t, valid, "Supposed to get true for samplecryptoSuite.Verify") + assert.Empty(t, err, "Not supposed to get error for samplecryptoSuite.Verify") + assert.True(t, valid, "Supposed to get true for samplecryptoSuite.Verify") } /* diff --git a/pkg/core/cryptosuite/cryptosuite_test.go b/pkg/core/cryptosuite/cryptosuite_test.go index bf2be8950d..cf316132c4 100644 --- a/pkg/core/cryptosuite/cryptosuite_test.go +++ b/pkg/core/cryptosuite/cryptosuite_test.go @@ -12,7 +12,7 @@ import ( "sync/atomic" "github.com/hyperledger/fabric-sdk-go/pkg/core/cryptosuite/bccsp/sw" - "github.com/hyperledger/fabric-sdk-go/pkg/logging/testutils" + "github.com/stretchr/testify/assert" ) const ( @@ -26,32 +26,32 @@ const ( func TestGetDefault(t *testing.T) { //At the beginning default suite is nil if no attempts have been made to set or get one - testutils.VerifyEmpty(t, defaultCryptoSuite, "default suite should be nil if no attempts have been made to set or get one") + assert.Empty(t, defaultCryptoSuite, "default suite should be nil if no attempts have been made to set or get one") //Now try to get default, it will create one and return defSuite := GetDefault() - testutils.VerifyNotEmpty(t, defSuite, "Not supposed to be nil defaultCryptSuite") - testutils.VerifyNotEmpty(t, defaultCryptoSuite, "default suite should have been initialized") - testutils.VerifyTrue(t, atomic.LoadInt32(&initialized) > 0, "'initialized' flag supposed to be set to 1") + assert.NotEmpty(t, defSuite, "Not supposed to be nil defaultCryptSuite") + assert.NotEmpty(t, defaultCryptoSuite, "default suite should have been initialized") + assert.True(t, atomic.LoadInt32(&initialized) > 0, "'initialized' flag supposed to be set to 1") hashbytes, err := defSuite.Hash([]byte("Sample message"), GetSHAOpts()) - testutils.VerifyEmpty(t, err, "Not supposed to get error on defaultCryptSuite.Hash() call : %s", err) - testutils.VerifyNotEmpty(t, hashbytes, "Supposed to get valid hash from defaultCryptSuite.Hash()") + assert.Empty(t, err, "Not supposed to get error on defaultCryptSuite.Hash() call : %s", err) + assert.NotEmpty(t, hashbytes, "Supposed to get valid hash from defaultCryptSuite.Hash()") //Now try to get default, which is already created defSuite = GetDefault() - testutils.VerifyNotEmpty(t, defSuite, "Not supposed to be nil defaultCryptSuite") - testutils.VerifyNotEmpty(t, defaultCryptoSuite, "default suite should have been initialized") - testutils.VerifyTrue(t, atomic.LoadInt32(&initialized) > 0, "'initialized' flag supposed to be set to 1") + assert.NotEmpty(t, defSuite, "Not supposed to be nil defaultCryptSuite") + assert.NotEmpty(t, defaultCryptoSuite, "default suite should have been initialized") + assert.True(t, atomic.LoadInt32(&initialized) > 0, "'initialized' flag supposed to be set to 1") hashbytes, err = defSuite.Hash([]byte("Sample message"), GetSHAOpts()) - testutils.VerifyEmpty(t, err, "Not supposed to get error on defaultCryptSuite.Hash() call : %s", err) - testutils.VerifyNotEmpty(t, hashbytes, "Supposed to get valid hash from defaultCryptSuite.Hash()") + assert.Empty(t, err, "Not supposed to get error on defaultCryptSuite.Hash() call : %s", err) + assert.NotEmpty(t, hashbytes, "Supposed to get valid hash from defaultCryptSuite.Hash()") //Now attempt to set default suite err = SetDefault(nil) - testutils.VerifyNotEmpty(t, err, "supposed to get error when SetDefault() gets called after GetDefault()") - testutils.VerifyTrue(t, err.Error() == setDefAlreadySetErrorMsg, "unexpected error : expected [%s], got [%s]", setDefAlreadySetErrorMsg, err.Error()) + assert.NotEmpty(t, err, "supposed to get error when SetDefault() gets called after GetDefault()") + assert.True(t, err.Error() == setDefAlreadySetErrorMsg, "unexpected error : expected [%s], got [%s]", setDefAlreadySetErrorMsg, err.Error()) //Reset defaultCryptoSuite = nil @@ -59,8 +59,8 @@ func TestGetDefault(t *testing.T) { //Now attempt to set invalid default suite err = SetDefault(nil) - testutils.VerifyNotEmpty(t, err, "supposed to get error when invalid default suite is set") - testutils.VerifyTrue(t, err.Error() == InvalidDefSuiteSetErrorMsg, "unexpected error : expected [%s], got [%s]", InvalidDefSuiteSetErrorMsg, err.Error()) + assert.NotEmpty(t, err, "supposed to get error when invalid default suite is set") + assert.True(t, err.Error() == InvalidDefSuiteSetErrorMsg, "unexpected error : expected [%s], got [%s]", InvalidDefSuiteSetErrorMsg, err.Error()) s, err := sw.GetSuiteWithDefaultEphemeral() if err != nil { @@ -68,7 +68,7 @@ func TestGetDefault(t *testing.T) { } err = SetDefault(s) - testutils.VerifyEmpty(t, err, "Not supposed to get error when valid default suite is set") + assert.Empty(t, err, "Not supposed to get error when valid default suite is set") } @@ -76,26 +76,26 @@ func TestHashOpts(t *testing.T) { //Get CryptoSuite SHA Opts hashOpts := GetSHAOpts() - testutils.VerifyNotEmpty(t, hashOpts, "Not supposed to be empty shaHashOpts") - testutils.VerifyTrue(t, hashOpts.Algorithm() == shaHashOptsAlgorithm, "Unexpected SHA hash opts, expected [%s], got [%s]", shaHashOptsAlgorithm, hashOpts.Algorithm()) + assert.NotZero(t, hashOpts, "Not supposed to be empty shaHashOpts") + assert.True(t, hashOpts.Algorithm() == shaHashOptsAlgorithm, "Unexpected SHA hash opts, expected [%s], got [%s]", shaHashOptsAlgorithm, hashOpts.Algorithm()) //Get CryptoSuite SHA256 Opts hashOpts = GetSHA256Opts() - testutils.VerifyNotEmpty(t, hashOpts, "Not supposed to be empty sha256HashOpts") - testutils.VerifyTrue(t, hashOpts.Algorithm() == sha256HashOptsAlgorithm, "Unexpected SHA hash opts, expected [%v], got [%v]", sha256HashOptsAlgorithm, hashOpts.Algorithm()) + assert.NotZero(t, hashOpts, "Not supposed to be empty sha256HashOpts") + assert.True(t, hashOpts.Algorithm() == sha256HashOptsAlgorithm, "Unexpected SHA hash opts, expected [%v], got [%v]", sha256HashOptsAlgorithm, hashOpts.Algorithm()) } func TestKeyGenOpts(t *testing.T) { keygenOpts := GetECDSAP256KeyGenOpts(true) - testutils.VerifyNotEmpty(t, keygenOpts, "Not supposed to be empty ECDSAP256KeyGenOpts") - testutils.VerifyTrue(t, keygenOpts.Ephemeral(), "Expected keygenOpts.Ephemeral() ==> true") - testutils.VerifyTrue(t, keygenOpts.Algorithm() == ecdsap256KeyGenOpts, "Unexpected SHA hash opts, expected [%v], got [%v]", ecdsap256KeyGenOpts, keygenOpts.Algorithm()) + assert.NotEmpty(t, keygenOpts, "Not supposed to be empty ECDSAP256KeyGenOpts") + assert.True(t, keygenOpts.Ephemeral(), "Expected keygenOpts.Ephemeral() ==> true") + assert.True(t, keygenOpts.Algorithm() == ecdsap256KeyGenOpts, "Unexpected SHA hash opts, expected [%v], got [%v]", ecdsap256KeyGenOpts, keygenOpts.Algorithm()) keygenOpts = GetECDSAP256KeyGenOpts(false) - testutils.VerifyNotEmpty(t, keygenOpts, "Not supposed to be empty ECDSAP256KeyGenOpts") - testutils.VerifyFalse(t, keygenOpts.Ephemeral(), "Expected keygenOpts.Ephemeral() ==> false") - testutils.VerifyTrue(t, keygenOpts.Algorithm() == ecdsap256KeyGenOpts, "Unexpected SHA hash opts, expected [%v], got [%v]", ecdsap256KeyGenOpts, keygenOpts.Algorithm()) + assert.NotZero(t, keygenOpts, "Not supposed to be empty ECDSAP256KeyGenOpts") + assert.False(t, keygenOpts.Ephemeral(), "Expected keygenOpts.Ephemeral() ==> false") + assert.True(t, keygenOpts.Algorithm() == ecdsap256KeyGenOpts, "Unexpected SHA hash opts, expected [%v], got [%v]", ecdsap256KeyGenOpts, keygenOpts.Algorithm()) } diff --git a/pkg/fab/comm/connection.go b/pkg/fab/comm/connection.go index 0111145855..4393378e21 100755 --- a/pkg/fab/comm/connection.go +++ b/pkg/fab/comm/connection.go @@ -13,11 +13,11 @@ import ( "github.com/pkg/errors" fabcontext "github.com/hyperledger/fabric-sdk-go/pkg/common/context" + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" "github.com/hyperledger/fabric-sdk-go/pkg/context/api/core" "github.com/hyperledger/fabric-sdk-go/pkg/core/config/comm" "github.com/hyperledger/fabric-sdk-go/pkg/core/config/urlutil" "github.com/hyperledger/fabric-sdk-go/pkg/logging" - "github.com/hyperledger/fabric-sdk-go/pkg/options" "google.golang.org/grpc" "google.golang.org/grpc/credentials" ) diff --git a/pkg/fab/comm/connectionopts.go b/pkg/fab/comm/connectionopts.go index 6fff911ca0..7987027829 100644 --- a/pkg/fab/comm/connectionopts.go +++ b/pkg/fab/comm/connectionopts.go @@ -10,7 +10,7 @@ import ( "crypto/x509" "time" - "github.com/hyperledger/fabric-sdk-go/pkg/options" + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" "google.golang.org/grpc/keepalive" ) diff --git a/pkg/fab/events/client/client.go b/pkg/fab/events/client/client.go index 3c427d8af3..63a318fb6c 100755 --- a/pkg/fab/events/client/client.go +++ b/pkg/fab/events/client/client.go @@ -11,11 +11,11 @@ import ( "sync/atomic" "time" + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" "github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client/dispatcher" eventservice "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/service" "github.com/hyperledger/fabric-sdk-go/pkg/logging" - "github.com/hyperledger/fabric-sdk-go/pkg/options" "github.com/pkg/errors" ) diff --git a/pkg/fab/events/client/client_test.go b/pkg/fab/events/client/client_test.go index 8bdc7a4e89..5d74ee2a3c 100755 --- a/pkg/fab/events/client/client_test.go +++ b/pkg/fab/events/client/client_test.go @@ -15,9 +15,8 @@ import ( "time" "github.com/hyperledger/fabric-sdk-go/pkg/common/context" - + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" "github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab" - "github.com/hyperledger/fabric-sdk-go/pkg/options" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/api" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client/dispatcher" diff --git a/pkg/fab/events/client/dispatcher/dispatcher.go b/pkg/fab/events/client/dispatcher/dispatcher.go index 40a5bdad3c..b43e136468 100755 --- a/pkg/fab/events/client/dispatcher/dispatcher.go +++ b/pkg/fab/events/client/dispatcher/dispatcher.go @@ -13,10 +13,10 @@ import ( "github.com/hyperledger/fabric-sdk-go/pkg/context/api/core" "github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab" + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/api" esdispatcher "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/service/dispatcher" "github.com/hyperledger/fabric-sdk-go/pkg/logging" - "github.com/hyperledger/fabric-sdk-go/pkg/options" "github.com/pkg/errors" ) diff --git a/pkg/fab/events/client/dispatcher/opts.go b/pkg/fab/events/client/dispatcher/opts.go index 3386af697c..d035dd2f57 100755 --- a/pkg/fab/events/client/dispatcher/opts.go +++ b/pkg/fab/events/client/dispatcher/opts.go @@ -7,8 +7,8 @@ SPDX-License-Identifier: Apache-2.0 package dispatcher import ( + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client/lbp" - "github.com/hyperledger/fabric-sdk-go/pkg/options" ) type params struct { diff --git a/pkg/fab/events/client/opts.go b/pkg/fab/events/client/opts.go index 4deb8a7082..9dc12a78d5 100755 --- a/pkg/fab/events/client/opts.go +++ b/pkg/fab/events/client/opts.go @@ -9,8 +9,8 @@ package client import ( "time" + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" "github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab" - "github.com/hyperledger/fabric-sdk-go/pkg/options" ) type params struct { diff --git a/pkg/fab/events/deliverclient/connection/connection.go b/pkg/fab/events/deliverclient/connection/connection.go index d5036e8df7..fe6dddb505 100755 --- a/pkg/fab/events/deliverclient/connection/connection.go +++ b/pkg/fab/events/deliverclient/connection/connection.go @@ -15,10 +15,10 @@ import ( "github.com/golang/protobuf/proto" fabcontext "github.com/hyperledger/fabric-sdk-go/pkg/common/context" + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" "github.com/hyperledger/fabric-sdk-go/pkg/fab/comm" clientdisp "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client/dispatcher" "github.com/hyperledger/fabric-sdk-go/pkg/logging" - "github.com/hyperledger/fabric-sdk-go/pkg/options" "github.com/pkg/errors" "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/crypto" diff --git a/pkg/fab/events/deliverclient/deliverclient.go b/pkg/fab/events/deliverclient/deliverclient.go index a4c59de363..956987e1b2 100755 --- a/pkg/fab/events/deliverclient/deliverclient.go +++ b/pkg/fab/events/deliverclient/deliverclient.go @@ -13,6 +13,7 @@ import ( ab "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protos/orderer" fabcontext "github.com/hyperledger/fabric-sdk-go/pkg/common/context" + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" "github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/api" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client" @@ -20,7 +21,6 @@ import ( "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/deliverclient/dispatcher" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/deliverclient/seek" "github.com/hyperledger/fabric-sdk-go/pkg/logging" - "github.com/hyperledger/fabric-sdk-go/pkg/options" "github.com/pkg/errors" ) diff --git a/pkg/fab/events/deliverclient/deliverclient_test.go b/pkg/fab/events/deliverclient/deliverclient_test.go index 716648568c..452a9c3c7e 100755 --- a/pkg/fab/events/deliverclient/deliverclient_test.go +++ b/pkg/fab/events/deliverclient/deliverclient_test.go @@ -11,6 +11,7 @@ import ( "time" fabcontext "github.com/hyperledger/fabric-sdk-go/pkg/common/context" + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" "github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client/dispatcher" @@ -20,7 +21,6 @@ import ( esdispatcher "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/service/dispatcher" servicemocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/service/mocks" fabclientmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks" - "github.com/hyperledger/fabric-sdk-go/pkg/options" cb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer" "github.com/pkg/errors" diff --git a/pkg/fab/events/deliverclient/dispatcher/dispatcher.go b/pkg/fab/events/deliverclient/dispatcher/dispatcher.go index 9c0527c13b..c35420368e 100755 --- a/pkg/fab/events/deliverclient/dispatcher/dispatcher.go +++ b/pkg/fab/events/deliverclient/dispatcher/dispatcher.go @@ -9,12 +9,12 @@ package dispatcher import ( ab "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protos/orderer" fabcontext "github.com/hyperledger/fabric-sdk-go/pkg/common/context" + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" "github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/api" clientdisp "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client/dispatcher" esdispatcher "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/service/dispatcher" "github.com/hyperledger/fabric-sdk-go/pkg/logging" - "github.com/hyperledger/fabric-sdk-go/pkg/options" cb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer" "github.com/pkg/errors" diff --git a/pkg/fab/events/deliverclient/opts.go b/pkg/fab/events/deliverclient/opts.go index 66543ea2a9..1a3f574b8d 100755 --- a/pkg/fab/events/deliverclient/opts.go +++ b/pkg/fab/events/deliverclient/opts.go @@ -9,9 +9,9 @@ package deliverclient import ( "time" + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/api" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/deliverclient/seek" - "github.com/hyperledger/fabric-sdk-go/pkg/options" ) type params struct { diff --git a/pkg/fab/events/eventhubclient/connection/connection.go b/pkg/fab/events/eventhubclient/connection/connection.go index 8cba24456d..00c92655b5 100755 --- a/pkg/fab/events/eventhubclient/connection/connection.go +++ b/pkg/fab/events/eventhubclient/connection/connection.go @@ -18,10 +18,10 @@ import ( "github.com/golang/protobuf/proto" "github.com/golang/protobuf/ptypes" + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" comm "github.com/hyperledger/fabric-sdk-go/pkg/fab/comm" clientdisp "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client/dispatcher" logging "github.com/hyperledger/fabric-sdk-go/pkg/logging" - "github.com/hyperledger/fabric-sdk-go/pkg/options" pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer" "github.com/pkg/errors" ) diff --git a/pkg/fab/events/eventhubclient/dispatcher/dispatcher.go b/pkg/fab/events/eventhubclient/dispatcher/dispatcher.go index 571b2072db..52d504ae5a 100755 --- a/pkg/fab/events/eventhubclient/dispatcher/dispatcher.go +++ b/pkg/fab/events/eventhubclient/dispatcher/dispatcher.go @@ -8,12 +8,12 @@ package dispatcher import ( "github.com/hyperledger/fabric-sdk-go/pkg/common/context" + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" "github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/api" clientdisp "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client/dispatcher" esdispatcher "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/service/dispatcher" "github.com/hyperledger/fabric-sdk-go/pkg/logging" - "github.com/hyperledger/fabric-sdk-go/pkg/options" pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer" "github.com/pkg/errors" ) diff --git a/pkg/fab/events/eventhubclient/eventhubclient.go b/pkg/fab/events/eventhubclient/eventhubclient.go index 0f085d7ee4..8195150f7e 100755 --- a/pkg/fab/events/eventhubclient/eventhubclient.go +++ b/pkg/fab/events/eventhubclient/eventhubclient.go @@ -16,9 +16,9 @@ import ( "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/eventhubclient/connection" + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/eventhubclient/dispatcher" "github.com/hyperledger/fabric-sdk-go/pkg/logging" - "github.com/hyperledger/fabric-sdk-go/pkg/options" "github.com/pkg/errors" ) diff --git a/pkg/fab/events/eventhubclient/eventhubclient_test.go b/pkg/fab/events/eventhubclient/eventhubclient_test.go index 5bde6f2308..f065b43be0 100755 --- a/pkg/fab/events/eventhubclient/eventhubclient_test.go +++ b/pkg/fab/events/eventhubclient/eventhubclient_test.go @@ -13,6 +13,7 @@ import ( "time" "github.com/hyperledger/fabric-sdk-go/pkg/common/context" + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" "github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/api" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client" @@ -24,7 +25,6 @@ import ( esdispatcher "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/service/dispatcher" servicemocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/service/mocks" fabmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks" - "github.com/hyperledger/fabric-sdk-go/pkg/options" cb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer" "github.com/pkg/errors" diff --git a/pkg/fab/events/eventhubclient/opts.go b/pkg/fab/events/eventhubclient/opts.go index 591451a759..a8b48d6137 100755 --- a/pkg/fab/events/eventhubclient/opts.go +++ b/pkg/fab/events/eventhubclient/opts.go @@ -9,8 +9,8 @@ package eventhubclient import ( "time" + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/api" - "github.com/hyperledger/fabric-sdk-go/pkg/options" pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer" ) diff --git a/pkg/fab/events/service/dispatcher/dispatcher.go b/pkg/fab/events/service/dispatcher/dispatcher.go index 38484a43ad..2946502b2c 100755 --- a/pkg/fab/events/service/dispatcher/dispatcher.go +++ b/pkg/fab/events/service/dispatcher/dispatcher.go @@ -14,9 +14,9 @@ import ( "time" "github.com/golang/protobuf/proto" + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" "github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab" "github.com/hyperledger/fabric-sdk-go/pkg/logging" - "github.com/hyperledger/fabric-sdk-go/pkg/options" ledgerutil "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/core/ledger/util" cb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common" pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer" diff --git a/pkg/fab/events/service/dispatcher/opts.go b/pkg/fab/events/service/dispatcher/opts.go index d1d8792142..6cef6e39b6 100755 --- a/pkg/fab/events/service/dispatcher/opts.go +++ b/pkg/fab/events/service/dispatcher/opts.go @@ -9,7 +9,7 @@ package dispatcher import ( "time" - "github.com/hyperledger/fabric-sdk-go/pkg/options" + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" ) type params struct { diff --git a/pkg/fab/events/service/service.go b/pkg/fab/events/service/service.go index d4362a1ecf..9380cc29b9 100755 --- a/pkg/fab/events/service/service.go +++ b/pkg/fab/events/service/service.go @@ -11,11 +11,11 @@ import ( "sync" "time" + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" "github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/service/blockfilter" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/service/dispatcher" logging "github.com/hyperledger/fabric-sdk-go/pkg/logging" - "github.com/hyperledger/fabric-sdk-go/pkg/options" "github.com/pkg/errors" ) diff --git a/pkg/fab/events/service/service_test.go b/pkg/fab/events/service/service_test.go index 2ff1e2cc22..40dea93d80 100755 --- a/pkg/fab/events/service/service_test.go +++ b/pkg/fab/events/service/service_test.go @@ -13,8 +13,8 @@ import ( "testing" "time" + "github.com/hyperledger/fabric-sdk-go/pkg/common/options" "github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab" - "github.com/hyperledger/fabric-sdk-go/pkg/options" "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/service/dispatcher" servicemocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/service/mocks" diff --git a/pkg/logging/api/logger.go b/pkg/logging/api/logger.go index c698ea4e58..423aaabb43 100644 --- a/pkg/logging/api/logger.go +++ b/pkg/logging/api/logger.go @@ -6,6 +6,18 @@ SPDX-License-Identifier: Apache-2.0 package api +// Level defines all available log levels for log messages. +type Level int + +// Log levels. +const ( + CRITICAL Level = iota + ERROR + WARNING + INFO + DEBUG +) + //Logger - Standard logger interface type Logger interface { Fatal(v ...interface{}) diff --git a/pkg/logging/decorator/callerInfo_test.go b/pkg/logging/decorator/callerInfo_test.go deleted file mode 100644 index ae98819f17..0000000000 --- a/pkg/logging/decorator/callerInfo_test.go +++ /dev/null @@ -1,44 +0,0 @@ -/* -Copyright SecureKey Technologies Inc. All Rights Reserved. - -SPDX-License-Identifier: Apache-2.0 -*/ - -package decorator - -import ( - "testing" - - "github.com/hyperledger/fabric-sdk-go/pkg/logging/loglevel" - "github.com/hyperledger/fabric-sdk-go/pkg/logging/testutils" -) - -func TestCallerInfoSetting(t *testing.T) { - - sampleCallerInfoSetting := CallerInfo{} - samppleModuleName := "sample-module-name" - - sampleCallerInfoSetting.ShowCallerInfo(samppleModuleName, loglevel.DEBUG) - testutils.VerifyTrue(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleModuleName, loglevel.DEBUG), "Callerinfo supposed to be enabled for this level") - - sampleCallerInfoSetting.HideCallerInfo(samppleModuleName, loglevel.DEBUG) - testutils.VerifyFalse(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleModuleName, loglevel.DEBUG), "Callerinfo supposed to be disabled for this level") - - //Reset existing caller info setting - sampleCallerInfoSetting.showcaller = nil - - //By default caller info should be disabled if not set - testutils.VerifyTrue(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleModuleName, loglevel.DEBUG), "Callerinfo supposed to be enabled for this level") - testutils.VerifyTrue(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleModuleName, loglevel.INFO), "Callerinfo supposed to be disabled for this level") - testutils.VerifyTrue(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleModuleName, loglevel.WARNING), "Callerinfo supposed to be disabled for this level") - testutils.VerifyTrue(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleModuleName, loglevel.ERROR), "Callerinfo supposed to be disabled for this level") - testutils.VerifyTrue(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleModuleName, loglevel.CRITICAL), "Callerinfo supposed to be disabled for this level") - - //By default caller info should be disabled if module name not found - samppleInvalidModuleName := "sample-module-name-doesnt-exists" - testutils.VerifyTrue(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleInvalidModuleName, loglevel.INFO), "Callerinfo supposed to be disabled for this level") - testutils.VerifyTrue(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleInvalidModuleName, loglevel.WARNING), "Callerinfo supposed to be disabled for this level") - testutils.VerifyTrue(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleInvalidModuleName, loglevel.ERROR), "Callerinfo supposed to be disabled for this level") - testutils.VerifyTrue(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleInvalidModuleName, loglevel.CRITICAL), "Callerinfo supposed to be disabled for this level") - testutils.VerifyTrue(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleInvalidModuleName, loglevel.DEBUG), "Callerinfo supposed to be disabled for this level") -} diff --git a/pkg/logging/logger.go b/pkg/logging/logger.go index 13bed4fd4c..3c2fd946ce 100644 --- a/pkg/logging/logger.go +++ b/pkg/logging/logger.go @@ -10,7 +10,7 @@ import ( "sync" "github.com/hyperledger/fabric-sdk-go/pkg/logging/api" - "github.com/hyperledger/fabric-sdk-go/pkg/logging/loglevel" + "github.com/hyperledger/fabric-sdk-go/pkg/logging/metadata" "github.com/hyperledger/fabric-sdk-go/pkg/logging/modlog" ) @@ -25,6 +25,18 @@ type Logger struct { var loggerProviderInstance api.LoggerProvider var loggerProviderOnce sync.Once +// Level defines all available log levels for log messages. +type Level int + +// Log levels. +const ( + CRITICAL Level = iota + ERROR + WARNING + INFO + DEBUG +) + // TODO: enable leveler to redirect to loggerProvider //var levelerProvider apilogging.Leveler @@ -77,23 +89,24 @@ func InitLogger(l api.LoggerProvider) { } //SetLevel - setting log level for given module -func SetLevel(module string, level loglevel.Level) { - modlog.SetLevel(module, level) +func SetLevel(module string, level Level) { + modlog.SetLevel(module, api.Level(level)) } //GetLevel - getting log level for given module -func GetLevel(module string) loglevel.Level { - return modlog.GetLevel(module) +func GetLevel(module string) Level { + return Level(modlog.GetLevel(module)) } //IsEnabledFor - Check if given log level is enabled for given module -func IsEnabledFor(module string, level loglevel.Level) bool { - return modlog.IsEnabledFor(module, level) +func IsEnabledFor(module string, level Level) bool { + return modlog.IsEnabledFor(module, api.Level(level)) } // LogLevel returns the log level from a string representation. -func LogLevel(level string) (loglevel.Level, error) { - return loglevel.ParseLevel(level) +func LogLevel(level string) (Level, error) { + l, err := metadata.ParseLevel(level) + return Level(l), err } //Fatal calls Fatal function of underlying logger @@ -207,3 +220,14 @@ func (l *Logger) logger() api.Logger { }) return l.instance } + +// ParseLevel returns the log level from a string representation. +func ParseLevel(level string) (Level, error) { + l, err := metadata.ParseLevel(level) + return Level(l), err +} + +//ParseString returns String repressentation of given log level +func ParseString(level Level) string { + return metadata.ParseString(api.Level(level)) +} diff --git a/pkg/logging/logger_test.go b/pkg/logging/logger_test.go index 8c549638a6..baf5d96ca7 100644 --- a/pkg/logging/logger_test.go +++ b/pkg/logging/logger_test.go @@ -10,10 +10,10 @@ import ( "sync" "testing" - "github.com/hyperledger/fabric-sdk-go/pkg/logging/loglevel" + "github.com/hyperledger/fabric-sdk-go/pkg/logging/api" "github.com/hyperledger/fabric-sdk-go/pkg/logging/modlog" "github.com/hyperledger/fabric-sdk-go/pkg/logging/testdata" - "github.com/hyperledger/fabric-sdk-go/pkg/logging/testutils" + "github.com/stretchr/testify/assert" ) var moduleName = "module-xyz" @@ -30,42 +30,42 @@ func TestLoggingForCustomLogger(t *testing.T) { logger := NewLogger(moduleName) //Test logger.print outputs - modlog.VerifyBasicLogging(t, loglevel.INFO, logger.Print, nil, &buf, true, moduleName) - modlog.VerifyBasicLogging(t, loglevel.INFO, logger.Println, nil, &buf, true, moduleName) - modlog.VerifyBasicLogging(t, loglevel.INFO, nil, logger.Printf, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.INFO, logger.Print, nil, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.INFO, logger.Println, nil, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.INFO, nil, logger.Printf, &buf, true, moduleName) //Test logger.info outputs - modlog.VerifyBasicLogging(t, loglevel.INFO, logger.Info, nil, &buf, true, moduleName) - modlog.VerifyBasicLogging(t, loglevel.INFO, logger.Infoln, nil, &buf, true, moduleName) - modlog.VerifyBasicLogging(t, loglevel.INFO, nil, logger.Infof, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.INFO, logger.Info, nil, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.INFO, logger.Infoln, nil, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.INFO, nil, logger.Infof, &buf, true, moduleName) //Test logger.warn outputs - modlog.VerifyBasicLogging(t, loglevel.WARNING, logger.Warn, nil, &buf, true, moduleName) - modlog.VerifyBasicLogging(t, loglevel.WARNING, logger.Warnln, nil, &buf, true, moduleName) - modlog.VerifyBasicLogging(t, loglevel.WARNING, nil, logger.Warnf, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.WARNING, logger.Warn, nil, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.WARNING, logger.Warnln, nil, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.WARNING, nil, logger.Warnf, &buf, true, moduleName) //In middle of test, get new logger, it should still stick to custom logger logger = NewLogger(moduleName) //Test logger.error outputs - modlog.VerifyBasicLogging(t, loglevel.ERROR, logger.Error, nil, &buf, true, moduleName) - modlog.VerifyBasicLogging(t, loglevel.ERROR, logger.Errorln, nil, &buf, true, moduleName) - modlog.VerifyBasicLogging(t, loglevel.ERROR, nil, logger.Errorf, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.ERROR, logger.Error, nil, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.ERROR, logger.Errorln, nil, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.ERROR, nil, logger.Errorf, &buf, true, moduleName) //Test logger.debug outputs - modlog.VerifyBasicLogging(t, loglevel.DEBUG, logger.Debug, nil, &buf, true, moduleName) - modlog.VerifyBasicLogging(t, loglevel.DEBUG, logger.Debugln, nil, &buf, true, moduleName) - modlog.VerifyBasicLogging(t, loglevel.DEBUG, nil, logger.Debugf, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.DEBUG, logger.Debug, nil, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.DEBUG, logger.Debugln, nil, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.DEBUG, nil, logger.Debugf, &buf, true, moduleName) ////Test logger.fatal outputs - this custom logger doesn't cause os exit code 1 - modlog.VerifyBasicLogging(t, loglevel.CRITICAL, logger.Fatal, nil, &buf, true, moduleName) - modlog.VerifyBasicLogging(t, loglevel.CRITICAL, logger.Fatalln, nil, &buf, true, moduleName) - modlog.VerifyBasicLogging(t, loglevel.CRITICAL, nil, logger.Fatalf, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.CRITICAL, logger.Fatal, nil, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.CRITICAL, logger.Fatalln, nil, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.CRITICAL, nil, logger.Fatalf, &buf, true, moduleName) //Test logger.panic outputs - this custom logger doesn't cause panic - modlog.VerifyBasicLogging(t, loglevel.CRITICAL, logger.Panic, nil, &buf, true, moduleName) - modlog.VerifyBasicLogging(t, loglevel.CRITICAL, logger.Panicln, nil, &buf, true, moduleName) - modlog.VerifyBasicLogging(t, loglevel.CRITICAL, nil, logger.Panicf, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.CRITICAL, logger.Panic, nil, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.CRITICAL, logger.Panicln, nil, &buf, true, moduleName) + modlog.VerifyBasicLogging(t, api.CRITICAL, nil, logger.Panicf, &buf, true, moduleName) } @@ -82,7 +82,7 @@ func TestDefaultModulledLoggingBehavior(t *testing.T) { dlogger.instance.(*modlog.Log).ChangeOutput(&buf) //No level set for this module so log level should be info - testutils.VerifyTrue(t, loglevel.INFO == modlog.GetLevel(moduleName), " default log level is INFO") + assert.True(t, api.INFO == modlog.GetLevel(moduleName), " default log level is INFO") //Test logger.print outputs modlog.VerifyBasicLogging(t, -1, dlogger.Print, nil, &buf, false, moduleName) @@ -90,19 +90,19 @@ func TestDefaultModulledLoggingBehavior(t *testing.T) { modlog.VerifyBasicLogging(t, -1, nil, dlogger.Printf, &buf, false, moduleName) //Test logger.info outputs - modlog.VerifyBasicLogging(t, loglevel.INFO, dlogger.Info, nil, &buf, false, moduleName) - modlog.VerifyBasicLogging(t, loglevel.INFO, dlogger.Infoln, nil, &buf, false, moduleName) - modlog.VerifyBasicLogging(t, loglevel.INFO, nil, dlogger.Infof, &buf, false, moduleName) + modlog.VerifyBasicLogging(t, api.INFO, dlogger.Info, nil, &buf, false, moduleName) + modlog.VerifyBasicLogging(t, api.INFO, dlogger.Infoln, nil, &buf, false, moduleName) + modlog.VerifyBasicLogging(t, api.INFO, nil, dlogger.Infof, &buf, false, moduleName) //Test logger.warn outputs - modlog.VerifyBasicLogging(t, loglevel.WARNING, dlogger.Warn, nil, &buf, false, moduleName) - modlog.VerifyBasicLogging(t, loglevel.WARNING, dlogger.Warnln, nil, &buf, false, moduleName) - modlog.VerifyBasicLogging(t, loglevel.WARNING, nil, dlogger.Warnf, &buf, false, moduleName) + modlog.VerifyBasicLogging(t, api.WARNING, dlogger.Warn, nil, &buf, false, moduleName) + modlog.VerifyBasicLogging(t, api.WARNING, dlogger.Warnln, nil, &buf, false, moduleName) + modlog.VerifyBasicLogging(t, api.WARNING, nil, dlogger.Warnf, &buf, false, moduleName) //Test logger.error outputs - modlog.VerifyBasicLogging(t, loglevel.ERROR, dlogger.Error, nil, &buf, false, moduleName) - modlog.VerifyBasicLogging(t, loglevel.ERROR, dlogger.Errorln, nil, &buf, false, moduleName) - modlog.VerifyBasicLogging(t, loglevel.ERROR, nil, dlogger.Errorf, &buf, false, moduleName) + modlog.VerifyBasicLogging(t, api.ERROR, dlogger.Error, nil, &buf, false, moduleName) + modlog.VerifyBasicLogging(t, api.ERROR, dlogger.Errorln, nil, &buf, false, moduleName) + modlog.VerifyBasicLogging(t, api.ERROR, nil, dlogger.Errorf, &buf, false, moduleName) /* SINCE DEBUG LOG IS NOT YET ENABLED, LOG OUTPUT SHOULD BE EMPTY @@ -112,33 +112,33 @@ func TestDefaultModulledLoggingBehavior(t *testing.T) { dlogger.Debugln("brown fox jumps over the lazy dog") dlogger.Debugf("brown %s jumps over the lazy %s", "fox", "dog") - testutils.VerifyEmpty(t, buf.String(), "debug log isn't supposed to show up for info level") + assert.Empty(t, buf.String(), "debug log isn't supposed to show up for info level") //Should be false - testutils.VerifyFalse(t, modlog.IsEnabledFor(moduleName, loglevel.DEBUG), "logging.IsEnabled for is not working as expected, expected false but got true") + assert.False(t, modlog.IsEnabledFor(moduleName, api.DEBUG), "logging.IsEnabled for is not working as expected, expected false but got true") //Now change the log level to DEBUG - modlog.SetLevel(moduleName, loglevel.DEBUG) + modlog.SetLevel(moduleName, api.DEBUG) //Should be false - testutils.VerifyTrue(t, modlog.IsEnabledFor(moduleName, loglevel.DEBUG), "logging.IsEnabled for is not working as expected, expected true but got false") + assert.True(t, modlog.IsEnabledFor(moduleName, api.DEBUG), "logging.IsEnabled for is not working as expected, expected true but got false") //Test logger.debug outputs - modlog.VerifyBasicLogging(t, loglevel.DEBUG, dlogger.Debug, nil, &buf, false, moduleName) - modlog.VerifyBasicLogging(t, loglevel.DEBUG, dlogger.Debugln, nil, &buf, false, moduleName) - modlog.VerifyBasicLogging(t, loglevel.DEBUG, nil, dlogger.Debugf, &buf, false, moduleName) + modlog.VerifyBasicLogging(t, api.DEBUG, dlogger.Debug, nil, &buf, false, moduleName) + modlog.VerifyBasicLogging(t, api.DEBUG, dlogger.Debugln, nil, &buf, false, moduleName) + modlog.VerifyBasicLogging(t, api.DEBUG, nil, dlogger.Debugf, &buf, false, moduleName) } func TestLoggerSetting(t *testing.T) { resetLoggerInstance() logger := NewLogger(moduleName) - testutils.VerifyTrue(t, loggerProviderInstance == nil, "Logger is not supposed to be initialized now") + assert.True(t, loggerProviderInstance == nil, "Logger is not supposed to be initialized now") logger.Info("brown fox jumps over the lazy dog") - testutils.VerifyTrue(t, loggerProviderInstance != nil, "Logger is supposed to be initialized now") + assert.True(t, loggerProviderInstance != nil, "Logger is supposed to be initialized now") resetLoggerInstance() InitLogger(modlog.LoggerProvider()) - testutils.VerifyTrue(t, loggerProviderInstance != nil, "Logger is supposed to be initialized now") + assert.True(t, loggerProviderInstance != nil, "Logger is supposed to be initialized now") } func resetLoggerInstance() { @@ -158,40 +158,40 @@ func TestDefaultCustomModuledLoggingBehavior(t *testing.T) { dlogger.logger() //No level set for this module so log level should be info - testutils.VerifyTrue(t, loglevel.INFO == modlog.GetLevel(moduleName2), " default log level is INFO") + assert.True(t, api.INFO == modlog.GetLevel(moduleName2), " default log level is INFO") //Test logger.print outputs - modlog.VerifyBasicLogging(t, loglevel.INFO, dlogger.Print, nil, &buf, true, moduleName2) - modlog.VerifyBasicLogging(t, loglevel.INFO, dlogger.Println, nil, &buf, true, moduleName2) - modlog.VerifyBasicLogging(t, loglevel.INFO, nil, dlogger.Printf, &buf, true, moduleName2) + modlog.VerifyBasicLogging(t, api.INFO, dlogger.Print, nil, &buf, true, moduleName2) + modlog.VerifyBasicLogging(t, api.INFO, dlogger.Println, nil, &buf, true, moduleName2) + modlog.VerifyBasicLogging(t, api.INFO, nil, dlogger.Printf, &buf, true, moduleName2) //Test logger.info outputs - modlog.VerifyBasicLogging(t, loglevel.INFO, dlogger.Info, nil, &buf, true, moduleName2) - modlog.VerifyBasicLogging(t, loglevel.INFO, dlogger.Infoln, nil, &buf, true, moduleName2) - modlog.VerifyBasicLogging(t, loglevel.INFO, nil, dlogger.Infof, &buf, true, moduleName2) + modlog.VerifyBasicLogging(t, api.INFO, dlogger.Info, nil, &buf, true, moduleName2) + modlog.VerifyBasicLogging(t, api.INFO, dlogger.Infoln, nil, &buf, true, moduleName2) + modlog.VerifyBasicLogging(t, api.INFO, nil, dlogger.Infof, &buf, true, moduleName2) //Test logger.warn outputs - modlog.VerifyBasicLogging(t, loglevel.WARNING, dlogger.Warn, nil, &buf, true, moduleName2) - modlog.VerifyBasicLogging(t, loglevel.WARNING, dlogger.Warnln, nil, &buf, true, moduleName2) - modlog.VerifyBasicLogging(t, loglevel.WARNING, nil, dlogger.Warnf, &buf, true, moduleName2) + modlog.VerifyBasicLogging(t, api.WARNING, dlogger.Warn, nil, &buf, true, moduleName2) + modlog.VerifyBasicLogging(t, api.WARNING, dlogger.Warnln, nil, &buf, true, moduleName2) + modlog.VerifyBasicLogging(t, api.WARNING, nil, dlogger.Warnf, &buf, true, moduleName2) //Test logger.error outputs - modlog.VerifyBasicLogging(t, loglevel.ERROR, dlogger.Error, nil, &buf, true, moduleName2) - modlog.VerifyBasicLogging(t, loglevel.ERROR, dlogger.Errorln, nil, &buf, true, moduleName2) - modlog.VerifyBasicLogging(t, loglevel.ERROR, nil, dlogger.Errorf, &buf, true, moduleName2) + modlog.VerifyBasicLogging(t, api.ERROR, dlogger.Error, nil, &buf, true, moduleName2) + modlog.VerifyBasicLogging(t, api.ERROR, dlogger.Errorln, nil, &buf, true, moduleName2) + modlog.VerifyBasicLogging(t, api.ERROR, nil, dlogger.Errorf, &buf, true, moduleName2) //Should be false - testutils.VerifyFalse(t, modlog.IsEnabledFor(moduleName2, loglevel.DEBUG), "logging.IsEnabled for is not working as expected, expected false but got true") + assert.False(t, modlog.IsEnabledFor(moduleName2, api.DEBUG), "logging.IsEnabled for is not working as expected, expected false but got true") //Now change the log level to DEBUG - modlog.SetLevel(moduleName2, loglevel.DEBUG) + modlog.SetLevel(moduleName2, api.DEBUG) //Should be false - testutils.VerifyTrue(t, modlog.IsEnabledFor(moduleName2, loglevel.DEBUG), "logging.IsEnabled for is not working as expected, expected true but got false") + assert.True(t, modlog.IsEnabledFor(moduleName2, api.DEBUG), "logging.IsEnabled for is not working as expected, expected true but got false") //Test logger.debug outputs - modlog.VerifyBasicLogging(t, loglevel.DEBUG, dlogger.Debug, nil, &buf, true, moduleName2) - modlog.VerifyBasicLogging(t, loglevel.DEBUG, dlogger.Debugln, nil, &buf, true, moduleName2) - modlog.VerifyBasicLogging(t, loglevel.DEBUG, nil, dlogger.Debugf, &buf, true, moduleName2) + modlog.VerifyBasicLogging(t, api.DEBUG, dlogger.Debug, nil, &buf, true, moduleName2) + modlog.VerifyBasicLogging(t, api.DEBUG, dlogger.Debugln, nil, &buf, true, moduleName2) + modlog.VerifyBasicLogging(t, api.DEBUG, nil, dlogger.Debugf, &buf, true, moduleName2) } diff --git a/pkg/logging/loglevel/level.go b/pkg/logging/loglevel/level.go deleted file mode 100644 index 880e35eaa4..0000000000 --- a/pkg/logging/loglevel/level.go +++ /dev/null @@ -1,58 +0,0 @@ -/* -Copyright SecureKey Technologies Inc. All Rights Reserved. - -SPDX-License-Identifier: Apache-2.0 -*/ - -package loglevel - -// TODO: Leveler allows log levels to be enabled or disabled -//type Leveler interface { -// SetLevel(module string, level Level) -// GetLevel(module string) Level -// IsEnabledFor(module string, level Level) bool -// LogLevel(level string) (Level, error) -//} - -// Level defines all available log levels for log messages. -type Level int - -// Log levels. -const ( - CRITICAL Level = iota - ERROR - WARNING - INFO - DEBUG -) - -//ModuleLevels maintains log levels based on module -type ModuleLevels struct { - levels map[string]Level -} - -// GetLevel returns the log level for the given module. -func (l *ModuleLevels) GetLevel(module string) Level { - level, exists := l.levels[module] - if exists == false { - level, exists = l.levels[""] - // no configuration exists, default to info - if exists == false { - level = INFO - } - } - return level -} - -// SetLevel sets the log level for the given module. -func (l *ModuleLevels) SetLevel(module string, level Level) { - if l.levels == nil { - l.levels = make(map[string]Level) - } - l.levels[module] = level -} - -// IsEnabledFor will return true if logging is enabled for the given module. -func (l *ModuleLevels) IsEnabledFor(module string, level Level) bool { - return level <= l.GetLevel(module) -} diff --git a/pkg/logging/loglevel/level_test.go b/pkg/logging/loglevel/level_test.go deleted file mode 100644 index f6674aad97..0000000000 --- a/pkg/logging/loglevel/level_test.go +++ /dev/null @@ -1,53 +0,0 @@ -/* -Copyright SecureKey Technologies Inc. All Rights Reserved. - -SPDX-License-Identifier: Apache-2.0 -*/ -package loglevel - -import ( - "testing" - - "github.com/hyperledger/fabric-sdk-go/pkg/logging/testutils" -) - -func TestLogLevels(t *testing.T) { - - mlevel := ModuleLevels{} - - mlevel.SetLevel("module-xyz-info", INFO) - mlevel.SetLevel("module-xyz-debug", DEBUG) - mlevel.SetLevel("module-xyz-error", ERROR) - mlevel.SetLevel("module-xyz-warning", WARNING) - - //Run info level checks - testutils.VerifyTrue(t, mlevel.IsEnabledFor("module-xyz-info", INFO)) - testutils.VerifyFalse(t, mlevel.IsEnabledFor("module-xyz-info", DEBUG)) - testutils.VerifyTrue(t, mlevel.IsEnabledFor("module-xyz-info", ERROR)) - testutils.VerifyTrue(t, mlevel.IsEnabledFor("module-xyz-info", WARNING)) - - //Run debug level checks - testutils.VerifyTrue(t, mlevel.IsEnabledFor("module-xyz-debug", INFO)) - testutils.VerifyTrue(t, mlevel.IsEnabledFor("module-xyz-debug", DEBUG)) - testutils.VerifyTrue(t, mlevel.IsEnabledFor("module-xyz-debug", ERROR)) - testutils.VerifyTrue(t, mlevel.IsEnabledFor("module-xyz-debug", WARNING)) - - //Run info level checks - testutils.VerifyFalse(t, mlevel.IsEnabledFor("module-xyz-error", INFO)) - testutils.VerifyFalse(t, mlevel.IsEnabledFor("module-xyz-error", DEBUG)) - testutils.VerifyTrue(t, mlevel.IsEnabledFor("module-xyz-error", ERROR)) - testutils.VerifyFalse(t, mlevel.IsEnabledFor("module-xyz-error", WARNING)) - - //Run info level checks - testutils.VerifyFalse(t, mlevel.IsEnabledFor("module-xyz-warning", INFO)) - testutils.VerifyFalse(t, mlevel.IsEnabledFor("module-xyz-warning", DEBUG)) - testutils.VerifyTrue(t, mlevel.IsEnabledFor("module-xyz-warning", ERROR)) - testutils.VerifyTrue(t, mlevel.IsEnabledFor("module-xyz-warning", WARNING)) - - //Run default log level check --> which is info currently - testutils.VerifyTrue(t, mlevel.IsEnabledFor("module-xyz-random-module", INFO)) - testutils.VerifyFalse(t, mlevel.IsEnabledFor("module-xyz-random-module", DEBUG)) - testutils.VerifyTrue(t, mlevel.IsEnabledFor("module-xyz-random-module", ERROR)) - testutils.VerifyTrue(t, mlevel.IsEnabledFor("module-xyz-random-module", WARNING)) - -} diff --git a/pkg/logging/decorator/callerInfo.go b/pkg/logging/metadata/callerInfo.go similarity index 67% rename from pkg/logging/decorator/callerInfo.go rename to pkg/logging/metadata/callerInfo.go index 500e0b010b..074886c469 100644 --- a/pkg/logging/decorator/callerInfo.go +++ b/pkg/logging/metadata/callerInfo.go @@ -4,15 +4,13 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package decorator +package metadata -import ( - "github.com/hyperledger/fabric-sdk-go/pkg/logging/loglevel" -) +import "github.com/hyperledger/fabric-sdk-go/pkg/logging/api" type callerInfoKey struct { module string - level loglevel.Level + level api.Level } //CallerInfo maintains module-level based information to toggle caller info @@ -21,7 +19,7 @@ type CallerInfo struct { } //ShowCallerInfo enables caller info for given module and level -func (l *CallerInfo) ShowCallerInfo(module string, level loglevel.Level) { +func (l *CallerInfo) ShowCallerInfo(module string, level api.Level) { if l.showcaller == nil { l.showcaller = l.getDefaultCallerInfoSetting() } @@ -29,7 +27,7 @@ func (l *CallerInfo) ShowCallerInfo(module string, level loglevel.Level) { } //HideCallerInfo disables caller info for given module and level -func (l *CallerInfo) HideCallerInfo(module string, level loglevel.Level) { +func (l *CallerInfo) HideCallerInfo(module string, level api.Level) { if l.showcaller == nil { l.showcaller = l.getDefaultCallerInfoSetting() } @@ -37,7 +35,7 @@ func (l *CallerInfo) HideCallerInfo(module string, level loglevel.Level) { } //IsCallerInfoEnabled returns if callerinfo enabled for given module and level -func (l *CallerInfo) IsCallerInfoEnabled(module string, level loglevel.Level) bool { +func (l *CallerInfo) IsCallerInfoEnabled(module string, level api.Level) bool { showcaller, exists := l.showcaller[callerInfoKey{module, level}] if exists == false { //If no callerinfo setting exists, then look for default @@ -52,10 +50,10 @@ func (l *CallerInfo) IsCallerInfoEnabled(module string, level loglevel.Level) bo //getDefaultCallerInfoSetting default setting for callerinfo func (l *CallerInfo) getDefaultCallerInfoSetting() map[callerInfoKey]bool { return map[callerInfoKey]bool{ - callerInfoKey{"", loglevel.CRITICAL}: true, - callerInfoKey{"", loglevel.ERROR}: true, - callerInfoKey{"", loglevel.WARNING}: true, - callerInfoKey{"", loglevel.INFO}: true, - callerInfoKey{"", loglevel.DEBUG}: true, + callerInfoKey{"", api.CRITICAL}: true, + callerInfoKey{"", api.ERROR}: true, + callerInfoKey{"", api.WARNING}: true, + callerInfoKey{"", api.INFO}: true, + callerInfoKey{"", api.DEBUG}: true, } } diff --git a/pkg/logging/metadata/callerInfo_test.go b/pkg/logging/metadata/callerInfo_test.go new file mode 100644 index 0000000000..20c7bd0d24 --- /dev/null +++ b/pkg/logging/metadata/callerInfo_test.go @@ -0,0 +1,44 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package metadata + +import ( + "testing" + + "github.com/hyperledger/fabric-sdk-go/pkg/logging/api" + "github.com/stretchr/testify/assert" +) + +func TestCallerInfoSetting(t *testing.T) { + + sampleCallerInfoSetting := CallerInfo{} + samppleModuleName := "sample-module-name" + + sampleCallerInfoSetting.ShowCallerInfo(samppleModuleName, api.DEBUG) + assert.True(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleModuleName, api.DEBUG), "Callerinfo supposed to be enabled for this level") + + sampleCallerInfoSetting.HideCallerInfo(samppleModuleName, api.DEBUG) + assert.False(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleModuleName, api.DEBUG), "Callerinfo supposed to be disabled for this level") + + //Reset existing caller info setting + sampleCallerInfoSetting.showcaller = nil + + //By default caller info should be disabled if not set + assert.True(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleModuleName, api.DEBUG), "Callerinfo supposed to be enabled for this level") + assert.True(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleModuleName, api.INFO), "Callerinfo supposed to be disabled for this level") + assert.True(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleModuleName, api.WARNING), "Callerinfo supposed to be disabled for this level") + assert.True(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleModuleName, api.ERROR), "Callerinfo supposed to be disabled for this level") + assert.True(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleModuleName, api.CRITICAL), "Callerinfo supposed to be disabled for this level") + + //By default caller info should be disabled if module name not found + samppleInvalidModuleName := "sample-module-name-doesnt-exists" + assert.True(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleInvalidModuleName, api.INFO), "Callerinfo supposed to be disabled for this level") + assert.True(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleInvalidModuleName, api.WARNING), "Callerinfo supposed to be disabled for this level") + assert.True(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleInvalidModuleName, api.ERROR), "Callerinfo supposed to be disabled for this level") + assert.True(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleInvalidModuleName, api.CRITICAL), "Callerinfo supposed to be disabled for this level") + assert.True(t, sampleCallerInfoSetting.IsCallerInfoEnabled(samppleInvalidModuleName, api.DEBUG), "Callerinfo supposed to be disabled for this level") +} diff --git a/pkg/logging/metadata/level.go b/pkg/logging/metadata/level.go new file mode 100644 index 0000000000..2df62f83d2 --- /dev/null +++ b/pkg/logging/metadata/level.go @@ -0,0 +1,40 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package metadata + +import "github.com/hyperledger/fabric-sdk-go/pkg/logging/api" + +//ModuleLevels maintains log levels based on module +type ModuleLevels struct { + levels map[string]api.Level +} + +// GetLevel returns the log level for the given module. +func (l *ModuleLevels) GetLevel(module string) api.Level { + level, exists := l.levels[module] + if exists == false { + level, exists = l.levels[""] + // no configuration exists, default to info + if exists == false { + level = api.INFO + } + } + return level +} + +// SetLevel sets the log level for the given module. +func (l *ModuleLevels) SetLevel(module string, level api.Level) { + if l.levels == nil { + l.levels = make(map[string]api.Level) + } + l.levels[module] = level +} + +// IsEnabledFor will return true if logging is enabled for the given module. +func (l *ModuleLevels) IsEnabledFor(module string, level api.Level) bool { + return level <= l.GetLevel(module) +} diff --git a/pkg/logging/metadata/level_test.go b/pkg/logging/metadata/level_test.go new file mode 100644 index 0000000000..406d654bf2 --- /dev/null +++ b/pkg/logging/metadata/level_test.go @@ -0,0 +1,54 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ +package metadata + +import ( + "testing" + + "github.com/hyperledger/fabric-sdk-go/pkg/logging/api" + "github.com/stretchr/testify/assert" +) + +func TestLogLevels(t *testing.T) { + + mlevel := ModuleLevels{} + + mlevel.SetLevel("module-xyz-info", api.INFO) + mlevel.SetLevel("module-xyz-debug", api.DEBUG) + mlevel.SetLevel("module-xyz-error", api.ERROR) + mlevel.SetLevel("module-xyz-warning", api.WARNING) + + //Run info level checks + assert.True(t, mlevel.IsEnabledFor("module-xyz-info", api.INFO)) + assert.False(t, mlevel.IsEnabledFor("module-xyz-info", api.DEBUG)) + assert.True(t, mlevel.IsEnabledFor("module-xyz-info", api.ERROR)) + assert.True(t, mlevel.IsEnabledFor("module-xyz-info", api.WARNING)) + + //Run debug level checks + assert.True(t, mlevel.IsEnabledFor("module-xyz-debug", api.INFO)) + assert.True(t, mlevel.IsEnabledFor("module-xyz-debug", api.DEBUG)) + assert.True(t, mlevel.IsEnabledFor("module-xyz-debug", api.ERROR)) + assert.True(t, mlevel.IsEnabledFor("module-xyz-debug", api.WARNING)) + + //Run info level checks + assert.False(t, mlevel.IsEnabledFor("module-xyz-error", api.INFO)) + assert.False(t, mlevel.IsEnabledFor("module-xyz-error", api.DEBUG)) + assert.True(t, mlevel.IsEnabledFor("module-xyz-error", api.ERROR)) + assert.False(t, mlevel.IsEnabledFor("module-xyz-error", api.WARNING)) + + //Run info level checks + assert.False(t, mlevel.IsEnabledFor("module-xyz-warning", api.INFO)) + assert.False(t, mlevel.IsEnabledFor("module-xyz-warning", api.DEBUG)) + assert.True(t, mlevel.IsEnabledFor("module-xyz-warning", api.ERROR)) + assert.True(t, mlevel.IsEnabledFor("module-xyz-warning", api.WARNING)) + + //Run default log level check --> which is info currently + assert.True(t, mlevel.IsEnabledFor("module-xyz-random-module", api.INFO)) + assert.False(t, mlevel.IsEnabledFor("module-xyz-random-module", api.DEBUG)) + assert.True(t, mlevel.IsEnabledFor("module-xyz-random-module", api.ERROR)) + assert.True(t, mlevel.IsEnabledFor("module-xyz-random-module", api.WARNING)) + +} diff --git a/pkg/logging/loglevel/utils.go b/pkg/logging/metadata/utils.go similarity index 65% rename from pkg/logging/loglevel/utils.go rename to pkg/logging/metadata/utils.go index 4e9ad34a2c..d1f2d3eebb 100644 --- a/pkg/logging/loglevel/utils.go +++ b/pkg/logging/metadata/utils.go @@ -4,11 +4,13 @@ Copyright SecureKey Technologies Inc. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package loglevel +package metadata import ( "errors" "strings" + + "github.com/hyperledger/fabric-sdk-go/pkg/logging/api" ) //Log level names in string @@ -21,16 +23,16 @@ var levelNames = []string{ } // ParseLevel returns the log level from a string representation. -func ParseLevel(level string) (Level, error) { +func ParseLevel(level string) (api.Level, error) { for i, name := range levelNames { if strings.EqualFold(name, level) { - return Level(i), nil + return api.Level(i), nil } } - return ERROR, errors.New("logger: invalid log level") + return api.ERROR, errors.New("logger: invalid log level") } //ParseString returns String repressentation of given log level -func ParseString(level Level) string { +func ParseString(level api.Level) string { return levelNames[level] } diff --git a/pkg/logging/modlog/modlog.go b/pkg/logging/modlog/modlog.go index 710cd14398..5b9bc0d8db 100644 --- a/pkg/logging/modlog/modlog.go +++ b/pkg/logging/modlog/modlog.go @@ -21,13 +21,12 @@ import ( "sync/atomic" "github.com/hyperledger/fabric-sdk-go/pkg/logging/api" - "github.com/hyperledger/fabric-sdk-go/pkg/logging/decorator" - "github.com/hyperledger/fabric-sdk-go/pkg/logging/loglevel" + "github.com/hyperledger/fabric-sdk-go/pkg/logging/metadata" ) var rwmutex = &sync.RWMutex{} -var moduleLevels = &loglevel.ModuleLevels{} -var callerInfos = &decorator.CallerInfo{} +var moduleLevels = &metadata.ModuleLevels{} +var callerInfos = &metadata.CallerInfo{} var useCustomLogger int32 // default logger factory singleton @@ -80,42 +79,42 @@ const ( ) //SetLevel - setting log level for given module -func SetLevel(module string, level loglevel.Level) { +func SetLevel(module string, level api.Level) { rwmutex.Lock() defer rwmutex.Unlock() moduleLevels.SetLevel(module, level) } //GetLevel - getting log level for given module -func GetLevel(module string) loglevel.Level { +func GetLevel(module string) api.Level { rwmutex.RLock() defer rwmutex.RUnlock() return moduleLevels.GetLevel(module) } //IsEnabledFor - Check if given log level is enabled for given module -func IsEnabledFor(module string, level loglevel.Level) bool { +func IsEnabledFor(module string, level api.Level) bool { rwmutex.RLock() defer rwmutex.RUnlock() return moduleLevels.IsEnabledFor(module, level) } //ShowCallerInfo - Show caller info in log lines for given log level -func ShowCallerInfo(module string, level loglevel.Level) { +func ShowCallerInfo(module string, level api.Level) { rwmutex.Lock() defer rwmutex.Unlock() callerInfos.ShowCallerInfo(module, level) } //HideCallerInfo - Do not show caller info in log lines for given log level -func HideCallerInfo(module string, level loglevel.Level) { +func HideCallerInfo(module string, level api.Level) { rwmutex.Lock() defer rwmutex.Unlock() callerInfos.HideCallerInfo(module, level) } //getLoggerOpts - returns LoggerOpts which can be used for customization -func getLoggerOpts(module string, level loglevel.Level) *loggerOpts { +func getLoggerOpts(module string, level api.Level) *loggerOpts { rwmutex.RLock() defer rwmutex.RUnlock() return &loggerOpts{ @@ -126,67 +125,67 @@ func getLoggerOpts(module string, level loglevel.Level) *loggerOpts { // Fatal is CRITICAL log followed by a call to os.Exit(1). func (l *Log) Fatal(args ...interface{}) { - opts := getLoggerOpts(l.module, loglevel.CRITICAL) + opts := getLoggerOpts(l.module, api.CRITICAL) if l.loadCustomLogger() { l.customLogger.Fatal(args...) return } - l.log(opts, loglevel.CRITICAL, args...) + l.log(opts, api.CRITICAL, args...) l.deflogger.Fatal(args...) } // Fatalf is CRITICAL log formatted followed by a call to os.Exit(1). func (l *Log) Fatalf(format string, args ...interface{}) { - opts := getLoggerOpts(l.module, loglevel.CRITICAL) + opts := getLoggerOpts(l.module, api.CRITICAL) if l.loadCustomLogger() { l.customLogger.Fatalf(format, args...) return } - l.logf(opts, loglevel.CRITICAL, format, args...) + l.logf(opts, api.CRITICAL, format, args...) l.deflogger.Fatalf(format, args...) } // Fatalln is CRITICAL log ln followed by a call to os.Exit(1). func (l *Log) Fatalln(args ...interface{}) { - opts := getLoggerOpts(l.module, loglevel.CRITICAL) + opts := getLoggerOpts(l.module, api.CRITICAL) if l.loadCustomLogger() { l.customLogger.Fatalln(args...) return } - l.logln(opts, loglevel.CRITICAL, args...) + l.logln(opts, api.CRITICAL, args...) l.deflogger.Fatalln(args...) } // Panic is CRITICAL log followed by a call to panic() func (l *Log) Panic(args ...interface{}) { - opts := getLoggerOpts(l.module, loglevel.CRITICAL) + opts := getLoggerOpts(l.module, api.CRITICAL) if l.loadCustomLogger() { l.customLogger.Panic(args...) return } - l.log(opts, loglevel.CRITICAL, args...) + l.log(opts, api.CRITICAL, args...) l.deflogger.Panic(args...) } // Panicf is CRITICAL log formatted followed by a call to panic() func (l *Log) Panicf(format string, args ...interface{}) { - opts := getLoggerOpts(l.module, loglevel.CRITICAL) + opts := getLoggerOpts(l.module, api.CRITICAL) if l.loadCustomLogger() { l.customLogger.Panicf(format, args...) return } - l.logf(opts, loglevel.CRITICAL, format, args...) + l.logf(opts, api.CRITICAL, format, args...) l.deflogger.Panicf(format, args...) } // Panicln is CRITICAL log ln followed by a call to panic() func (l *Log) Panicln(args ...interface{}) { - opts := getLoggerOpts(l.module, loglevel.CRITICAL) + opts := getLoggerOpts(l.module, api.CRITICAL) if l.loadCustomLogger() { l.customLogger.Panicln(args...) return } - l.logln(opts, loglevel.CRITICAL, args...) + l.logln(opts, api.CRITICAL, args...) l.deflogger.Panicln(args...) } @@ -223,7 +222,7 @@ func (l *Log) Println(args ...interface{}) { // Debug calls go log.Output. // Arguments are handled in the manner of fmt.Print. func (l *Log) Debug(args ...interface{}) { - opts := getLoggerOpts(l.module, loglevel.DEBUG) + opts := getLoggerOpts(l.module, api.DEBUG) if !opts.levelEnabled { return } @@ -231,13 +230,13 @@ func (l *Log) Debug(args ...interface{}) { l.customLogger.Debug(args...) return } - l.log(opts, loglevel.DEBUG, args...) + l.log(opts, api.DEBUG, args...) } // Debugf calls go log.Output. // Arguments are handled in the manner of fmt.Printf. func (l *Log) Debugf(format string, args ...interface{}) { - opts := getLoggerOpts(l.module, loglevel.DEBUG) + opts := getLoggerOpts(l.module, api.DEBUG) if !opts.levelEnabled { return } @@ -245,13 +244,13 @@ func (l *Log) Debugf(format string, args ...interface{}) { l.customLogger.Debugf(format, args...) return } - l.logf(opts, loglevel.DEBUG, format, args...) + l.logf(opts, api.DEBUG, format, args...) } // Debugln calls go log.Output. // Arguments are handled in the manner of fmt.Println. func (l *Log) Debugln(args ...interface{}) { - opts := getLoggerOpts(l.module, loglevel.DEBUG) + opts := getLoggerOpts(l.module, api.DEBUG) if !opts.levelEnabled { return } @@ -259,13 +258,13 @@ func (l *Log) Debugln(args ...interface{}) { l.customLogger.Debugln(args...) return } - l.logln(opts, loglevel.DEBUG, args...) + l.logln(opts, api.DEBUG, args...) } // Info calls go log.Output. // Arguments are handled in the manner of fmt.Print. func (l *Log) Info(args ...interface{}) { - opts := getLoggerOpts(l.module, loglevel.INFO) + opts := getLoggerOpts(l.module, api.INFO) if !opts.levelEnabled { return } @@ -273,13 +272,13 @@ func (l *Log) Info(args ...interface{}) { l.customLogger.Info(args...) return } - l.log(opts, loglevel.INFO, args...) + l.log(opts, api.INFO, args...) } // Infof calls go log.Output. // Arguments are handled in the manner of fmt.Printf. func (l *Log) Infof(format string, args ...interface{}) { - opts := getLoggerOpts(l.module, loglevel.INFO) + opts := getLoggerOpts(l.module, api.INFO) if !opts.levelEnabled { return } @@ -287,13 +286,13 @@ func (l *Log) Infof(format string, args ...interface{}) { l.customLogger.Infof(format, args...) return } - l.logf(opts, loglevel.INFO, format, args...) + l.logf(opts, api.INFO, format, args...) } // Infoln calls go log.Output. // Arguments are handled in the manner of fmt.Println. func (l *Log) Infoln(args ...interface{}) { - opts := getLoggerOpts(l.module, loglevel.INFO) + opts := getLoggerOpts(l.module, api.INFO) if !opts.levelEnabled { return } @@ -301,13 +300,13 @@ func (l *Log) Infoln(args ...interface{}) { l.customLogger.Infoln(args...) return } - l.logln(opts, loglevel.INFO, args...) + l.logln(opts, api.INFO, args...) } // Warn calls go log.Output. // Arguments are handled in the manner of fmt.Print. func (l *Log) Warn(args ...interface{}) { - opts := getLoggerOpts(l.module, loglevel.WARNING) + opts := getLoggerOpts(l.module, api.WARNING) if !opts.levelEnabled { return } @@ -315,13 +314,13 @@ func (l *Log) Warn(args ...interface{}) { l.customLogger.Warn(args...) return } - l.log(opts, loglevel.WARNING, args...) + l.log(opts, api.WARNING, args...) } // Warnf calls go log.Output. // Arguments are handled in the manner of fmt.Printf. func (l *Log) Warnf(format string, args ...interface{}) { - opts := getLoggerOpts(l.module, loglevel.WARNING) + opts := getLoggerOpts(l.module, api.WARNING) if !opts.levelEnabled { return } @@ -329,13 +328,13 @@ func (l *Log) Warnf(format string, args ...interface{}) { l.customLogger.Warnf(format, args...) return } - l.logf(opts, loglevel.WARNING, format, args...) + l.logf(opts, api.WARNING, format, args...) } // Warnln calls go log.Output. // Arguments are handled in the manner of fmt.Println. func (l *Log) Warnln(args ...interface{}) { - opts := getLoggerOpts(l.module, loglevel.WARNING) + opts := getLoggerOpts(l.module, api.WARNING) if !opts.levelEnabled { return } @@ -343,13 +342,13 @@ func (l *Log) Warnln(args ...interface{}) { l.customLogger.Warnln(args...) return } - l.logln(opts, loglevel.WARNING, args...) + l.logln(opts, api.WARNING, args...) } // Error calls go log.Output. // Arguments are handled in the manner of fmt.Print. func (l *Log) Error(args ...interface{}) { - opts := getLoggerOpts(l.module, loglevel.ERROR) + opts := getLoggerOpts(l.module, api.ERROR) if !opts.levelEnabled { return } @@ -357,13 +356,13 @@ func (l *Log) Error(args ...interface{}) { l.customLogger.Error(args...) return } - l.log(opts, loglevel.ERROR, args...) + l.log(opts, api.ERROR, args...) } // Errorf calls go log.Output. // Arguments are handled in the manner of fmt.Printf. func (l *Log) Errorf(format string, args ...interface{}) { - opts := getLoggerOpts(l.module, loglevel.ERROR) + opts := getLoggerOpts(l.module, api.ERROR) if !opts.levelEnabled { return } @@ -371,13 +370,13 @@ func (l *Log) Errorf(format string, args ...interface{}) { l.customLogger.Errorf(format, args...) return } - l.logf(opts, loglevel.ERROR, format, args...) + l.logf(opts, api.ERROR, format, args...) } // Errorln calls go log.Output. // Arguments are handled in the manner of fmt.Println. func (l *Log) Errorln(args ...interface{}) { - opts := getLoggerOpts(l.module, loglevel.ERROR) + opts := getLoggerOpts(l.module, api.ERROR) if !opts.levelEnabled { return } @@ -385,7 +384,7 @@ func (l *Log) Errorln(args ...interface{}) { l.customLogger.Errorln(args...) return } - l.logln(opts, loglevel.ERROR, args...) + l.logln(opts, api.ERROR, args...) } //ChangeOutput for changing output destination for the logger. @@ -393,21 +392,21 @@ func (l *Log) ChangeOutput(output io.Writer) { l.deflogger.SetOutput(output) } -func (l *Log) logf(opts *loggerOpts, level loglevel.Level, format string, args ...interface{}) { +func (l *Log) logf(opts *loggerOpts, level api.Level, format string, args ...interface{}) { //Format prefix to show function name and log level and to indicate that timezone used is UTC - customPrefix := fmt.Sprintf(logLevelFormatter, l.getCallerInfo(opts), loglevel.ParseString(level)) + customPrefix := fmt.Sprintf(logLevelFormatter, l.getCallerInfo(opts), metadata.ParseString(level)) l.deflogger.Output(2, customPrefix+fmt.Sprintf(format, args...)) } -func (l *Log) log(opts *loggerOpts, level loglevel.Level, args ...interface{}) { +func (l *Log) log(opts *loggerOpts, level api.Level, args ...interface{}) { //Format prefix to show function name and log level and to indicate that timezone used is UTC - customPrefix := fmt.Sprintf(logLevelFormatter, l.getCallerInfo(opts), loglevel.ParseString(level)) + customPrefix := fmt.Sprintf(logLevelFormatter, l.getCallerInfo(opts), metadata.ParseString(level)) l.deflogger.Output(2, customPrefix+fmt.Sprint(args...)) } -func (l *Log) logln(opts *loggerOpts, level loglevel.Level, args ...interface{}) { +func (l *Log) logln(opts *loggerOpts, level api.Level, args ...interface{}) { //Format prefix to show function name and log level and to indicate that timezone used is UTC - customPrefix := fmt.Sprintf(logLevelFormatter, l.getCallerInfo(opts), loglevel.ParseString(level)) + customPrefix := fmt.Sprintf(logLevelFormatter, l.getCallerInfo(opts), metadata.ParseString(level)) l.deflogger.Output(2, customPrefix+fmt.Sprintln(args...)) } diff --git a/pkg/logging/modlog/modlog_test.go b/pkg/logging/modlog/modlog_test.go index 69439e8354..49650f57e7 100644 --- a/pkg/logging/modlog/modlog_test.go +++ b/pkg/logging/modlog/modlog_test.go @@ -12,21 +12,22 @@ import ( "sync" - "github.com/hyperledger/fabric-sdk-go/pkg/logging/loglevel" + "github.com/hyperledger/fabric-sdk-go/pkg/logging/api" + "github.com/hyperledger/fabric-sdk-go/pkg/logging/metadata" "github.com/hyperledger/fabric-sdk-go/pkg/logging/testdata" - utils "github.com/hyperledger/fabric-sdk-go/pkg/logging/testutils" + "github.com/stretchr/testify/assert" ) //change the output to buffer for tests var buf bytes.Buffer func TestDefaultLoggingWithoutCallerInfo(t *testing.T) { - HideCallerInfo(moduleName, loglevel.WARNING) + HideCallerInfo(moduleName, api.WARNING) testDefaultLogging(t) } func TestDefaultLoggingWithCallerInfo(t *testing.T) { - ShowCallerInfo(moduleName, loglevel.WARNING) + ShowCallerInfo(moduleName, api.WARNING) testDefaultLogging(t) } @@ -38,7 +39,7 @@ func testDefaultLogging(t *testing.T) { logger.(*Log).ChangeOutput(&buf) //No level set for this module so log level should be info - utils.VerifyTrue(t, loglevel.INFO == GetLevel(moduleName), " default log level is INFO") + assert.True(t, api.INFO == GetLevel(moduleName), " default log level is INFO") //Test logger.print outputs VerifyBasicLogging(t, -1, logger.Print, nil, &buf, false, moduleName) @@ -46,19 +47,19 @@ func testDefaultLogging(t *testing.T) { VerifyBasicLogging(t, -1, nil, logger.Printf, &buf, false, moduleName) //Test logger.info outputs - VerifyBasicLogging(t, loglevel.INFO, logger.Info, nil, &buf, false, moduleName) - VerifyBasicLogging(t, loglevel.INFO, logger.Infoln, nil, &buf, false, moduleName) - VerifyBasicLogging(t, loglevel.INFO, nil, logger.Infof, &buf, false, moduleName) + VerifyBasicLogging(t, api.INFO, logger.Info, nil, &buf, false, moduleName) + VerifyBasicLogging(t, api.INFO, logger.Infoln, nil, &buf, false, moduleName) + VerifyBasicLogging(t, api.INFO, nil, logger.Infof, &buf, false, moduleName) //Test logger.warn outputs - VerifyBasicLogging(t, loglevel.WARNING, logger.Warn, nil, &buf, false, moduleName) - VerifyBasicLogging(t, loglevel.WARNING, logger.Warnln, nil, &buf, false, moduleName) - VerifyBasicLogging(t, loglevel.WARNING, nil, logger.Warnf, &buf, false, moduleName) + VerifyBasicLogging(t, api.WARNING, logger.Warn, nil, &buf, false, moduleName) + VerifyBasicLogging(t, api.WARNING, logger.Warnln, nil, &buf, false, moduleName) + VerifyBasicLogging(t, api.WARNING, nil, logger.Warnf, &buf, false, moduleName) //Test logger.error outputs - VerifyBasicLogging(t, loglevel.ERROR, logger.Error, nil, &buf, false, moduleName) - VerifyBasicLogging(t, loglevel.ERROR, logger.Errorln, nil, &buf, false, moduleName) - VerifyBasicLogging(t, loglevel.ERROR, nil, logger.Errorf, &buf, false, moduleName) + VerifyBasicLogging(t, api.ERROR, logger.Error, nil, &buf, false, moduleName) + VerifyBasicLogging(t, api.ERROR, logger.Errorln, nil, &buf, false, moduleName) + VerifyBasicLogging(t, api.ERROR, nil, logger.Errorf, &buf, false, moduleName) /* SINCE DEBUG LOG IS NOT YET ENABLED, LOG OUTPUT SHOULD BE EMPTY @@ -68,24 +69,24 @@ func testDefaultLogging(t *testing.T) { logger.Debugln("brown fox jumps over the lazy dog") logger.Debugf("brown %s jumps over the lazy %s", "fox", "dog") - utils.VerifyEmpty(t, buf.String(), "debug log isn't supposed to show up for info level") + assert.Empty(t, buf.String(), "debug log isn't supposed to show up for info level") //Should be false - utils.VerifyFalse(t, IsEnabledFor(moduleName, loglevel.DEBUG), "apiapilogging.IsEnabled for is not working as expected, expected false but got true") + assert.False(t, IsEnabledFor(moduleName, api.DEBUG), "apiapilogging.IsEnabled for is not working as expected, expected false but got true") //Now change the log level to apilogging.DEBUG - SetLevel(moduleName, loglevel.DEBUG) + SetLevel(moduleName, api.DEBUG) //Should be false - utils.VerifyTrue(t, IsEnabledFor(moduleName, loglevel.DEBUG), "apiapilogging.IsEnabled for is not working as expected, expected true but got false") + assert.True(t, IsEnabledFor(moduleName, api.DEBUG), "apiapilogging.IsEnabled for is not working as expected, expected true but got false") //Test logger.debug outputs - VerifyBasicLogging(t, loglevel.DEBUG, logger.Debug, nil, &buf, false, moduleName) - VerifyBasicLogging(t, loglevel.DEBUG, logger.Debugln, nil, &buf, false, moduleName) - VerifyBasicLogging(t, loglevel.DEBUG, nil, logger.Debugf, &buf, false, moduleName) + VerifyBasicLogging(t, api.DEBUG, logger.Debug, nil, &buf, false, moduleName) + VerifyBasicLogging(t, api.DEBUG, logger.Debugln, nil, &buf, false, moduleName) + VerifyBasicLogging(t, api.DEBUG, nil, logger.Debugf, &buf, false, moduleName) //Reset module levels for next test - moduleLevels = &loglevel.ModuleLevels{} + moduleLevels = &metadata.ModuleLevels{} } func TestDefaultLoggingPanic(t *testing.T) { @@ -96,9 +97,9 @@ func TestDefaultLoggingPanic(t *testing.T) { var buf bytes.Buffer logger.(*Log).ChangeOutput(&buf) - VerifyCriticalLoggings(t, loglevel.CRITICAL, logger.Panic, nil, &buf) - VerifyCriticalLoggings(t, loglevel.CRITICAL, logger.Panicln, nil, &buf) - VerifyCriticalLoggings(t, loglevel.CRITICAL, nil, logger.Panicf, &buf) + VerifyCriticalLoggings(t, api.CRITICAL, logger.Panic, nil, &buf) + VerifyCriticalLoggings(t, api.CRITICAL, logger.Panicln, nil, &buf) + VerifyCriticalLoggings(t, api.CRITICAL, nil, logger.Panicf, &buf) } @@ -117,41 +118,41 @@ func TestDefaultCustomModulledLogging(t *testing.T) { dlogger := LoggerProvider().GetLogger(moduleName2) //No level set for this module so log level should be info - utils.VerifyTrue(t, loglevel.INFO == GetLevel(moduleName2), " default log level is INFO") + assert.True(t, api.INFO == GetLevel(moduleName2), " default log level is INFO") //Test logger.print outputs - VerifyBasicLogging(t, loglevel.INFO, dlogger.Print, nil, &buf, true, moduleName2) - VerifyBasicLogging(t, loglevel.INFO, dlogger.Println, nil, &buf, true, moduleName2) - VerifyBasicLogging(t, loglevel.INFO, nil, dlogger.Printf, &buf, true, moduleName2) + VerifyBasicLogging(t, api.INFO, dlogger.Print, nil, &buf, true, moduleName2) + VerifyBasicLogging(t, api.INFO, dlogger.Println, nil, &buf, true, moduleName2) + VerifyBasicLogging(t, api.INFO, nil, dlogger.Printf, &buf, true, moduleName2) //Test logger.info outputs - VerifyBasicLogging(t, loglevel.INFO, dlogger.Info, nil, &buf, true, moduleName2) - VerifyBasicLogging(t, loglevel.INFO, dlogger.Infoln, nil, &buf, true, moduleName2) - VerifyBasicLogging(t, loglevel.INFO, nil, dlogger.Infof, &buf, true, moduleName2) + VerifyBasicLogging(t, api.INFO, dlogger.Info, nil, &buf, true, moduleName2) + VerifyBasicLogging(t, api.INFO, dlogger.Infoln, nil, &buf, true, moduleName2) + VerifyBasicLogging(t, api.INFO, nil, dlogger.Infof, &buf, true, moduleName2) //Test logger.warn outputs - VerifyBasicLogging(t, loglevel.WARNING, dlogger.Warn, nil, &buf, true, moduleName2) - VerifyBasicLogging(t, loglevel.WARNING, dlogger.Warnln, nil, &buf, true, moduleName2) - VerifyBasicLogging(t, loglevel.WARNING, nil, dlogger.Warnf, &buf, true, moduleName2) + VerifyBasicLogging(t, api.WARNING, dlogger.Warn, nil, &buf, true, moduleName2) + VerifyBasicLogging(t, api.WARNING, dlogger.Warnln, nil, &buf, true, moduleName2) + VerifyBasicLogging(t, api.WARNING, nil, dlogger.Warnf, &buf, true, moduleName2) //Test logger.error outputs - VerifyBasicLogging(t, loglevel.ERROR, dlogger.Error, nil, &buf, true, moduleName2) - VerifyBasicLogging(t, loglevel.ERROR, dlogger.Errorln, nil, &buf, true, moduleName2) - VerifyBasicLogging(t, loglevel.ERROR, nil, dlogger.Errorf, &buf, true, moduleName2) + VerifyBasicLogging(t, api.ERROR, dlogger.Error, nil, &buf, true, moduleName2) + VerifyBasicLogging(t, api.ERROR, dlogger.Errorln, nil, &buf, true, moduleName2) + VerifyBasicLogging(t, api.ERROR, nil, dlogger.Errorf, &buf, true, moduleName2) //Should be false - utils.VerifyFalse(t, IsEnabledFor(moduleName2, loglevel.DEBUG), "logging.IsEnabled for is not working as expected, expected false but got true") + assert.False(t, IsEnabledFor(moduleName2, api.DEBUG), "logging.IsEnabled for is not working as expected, expected false but got true") //Now change the log level to DEBUG - SetLevel(moduleName2, loglevel.DEBUG) + SetLevel(moduleName2, api.DEBUG) //Should be false - utils.VerifyTrue(t, IsEnabledFor(moduleName2, loglevel.DEBUG), "logging.IsEnabled for is not working as expected, expected true but got false") + assert.True(t, IsEnabledFor(moduleName2, api.DEBUG), "logging.IsEnabled for is not working as expected, expected true but got false") //Test logger.debug outputs - VerifyBasicLogging(t, loglevel.DEBUG, dlogger.Debug, nil, &buf, true, moduleName2) - VerifyBasicLogging(t, loglevel.DEBUG, dlogger.Debugln, nil, &buf, true, moduleName2) - VerifyBasicLogging(t, loglevel.DEBUG, nil, dlogger.Debugf, &buf, true, moduleName2) + VerifyBasicLogging(t, api.DEBUG, dlogger.Debug, nil, &buf, true, moduleName2) + VerifyBasicLogging(t, api.DEBUG, dlogger.Debugln, nil, &buf, true, moduleName2) + VerifyBasicLogging(t, api.DEBUG, nil, dlogger.Debugf, &buf, true, moduleName2) } @@ -164,8 +165,8 @@ func TestCustomDefaultLoggingPanic(t *testing.T) { //Get new logger logger := LoggerProvider().GetLogger(moduleName2) - VerifyBasicLogging(t, loglevel.CRITICAL, logger.Fatal, nil, &buf, true, moduleName2) - VerifyBasicLogging(t, loglevel.CRITICAL, logger.Fatalln, nil, &buf, true, moduleName2) - VerifyBasicLogging(t, loglevel.CRITICAL, nil, logger.Fatalf, &buf, true, moduleName2) + VerifyBasicLogging(t, api.CRITICAL, logger.Fatal, nil, &buf, true, moduleName2) + VerifyBasicLogging(t, api.CRITICAL, logger.Fatalln, nil, &buf, true, moduleName2) + VerifyBasicLogging(t, api.CRITICAL, nil, logger.Fatalf, &buf, true, moduleName2) } diff --git a/pkg/logging/modlog/testVerifyUtils.go b/pkg/logging/modlog/testVerifyUtils.go index 5e5b10862d..7923a995da 100644 --- a/pkg/logging/modlog/testVerifyUtils.go +++ b/pkg/logging/modlog/testVerifyUtils.go @@ -12,8 +12,9 @@ import ( "regexp" "testing" - "github.com/hyperledger/fabric-sdk-go/pkg/logging/loglevel" - utils "github.com/hyperledger/fabric-sdk-go/pkg/logging/testutils" + "github.com/hyperledger/fabric-sdk-go/pkg/logging/api" + "github.com/hyperledger/fabric-sdk-go/pkg/logging/metadata" + "github.com/stretchr/testify/assert" ) const ( @@ -29,7 +30,7 @@ type fn func(...interface{}) type fnf func(string, ...interface{}) //VerifyCriticalLoggings utility func which does job calling and verifying CRITICAL log level functions - PANIC -func VerifyCriticalLoggings(t *testing.T, level loglevel.Level, loggerFunc fn, loggerFuncf fnf, buf *bytes.Buffer) { +func VerifyCriticalLoggings(t *testing.T, level api.Level, loggerFunc fn, loggerFuncf fnf, buf *bytes.Buffer) { //Handling panic as well as checking log output defer func() { if r := recover(); r == nil { @@ -39,14 +40,14 @@ func VerifyCriticalLoggings(t *testing.T, level loglevel.Level, loggerFunc fn, l opts := getLoggerOpts(moduleName, level) if opts.callerInfoEnabled { //with caller info - regex = fmt.Sprintf(basicLevelOutputWithCallerInfoExpectedRegex, moduleName, loglevel.ParseString(level)) + regex = fmt.Sprintf(basicLevelOutputWithCallerInfoExpectedRegex, moduleName, metadata.ParseString(level)) } else { //without caller info - regex = fmt.Sprintf(basicLevelOutputExpectedRegex, moduleName, loglevel.ParseString(level)) + regex = fmt.Sprintf(basicLevelOutputExpectedRegex, moduleName, metadata.ParseString(level)) } match, err := regexp.MatchString(regex, buf.String()) - utils.VerifyEmpty(t, err, "error while matching regex with logoutput wasnt expected") - utils.VerifyTrue(t, match, "CRITICAL logger isn't producing output as expected, \n logoutput:%s\n regex: %s", buf.String(), regex) + assert.Empty(t, err, "error while matching regex with logoutput wasnt expected") + assert.True(t, match, "CRITICAL logger isn't producing output as expected, \n logoutput:%s\n regex: %s", buf.String(), regex) }() @@ -59,7 +60,7 @@ func VerifyCriticalLoggings(t *testing.T, level loglevel.Level, loggerFunc fn, l } //VerifyBasicLogging utility func which does job calling and verifying basic log level functions - DEBUG, INFO, ERROR, WARNING -func VerifyBasicLogging(t *testing.T, level loglevel.Level, loggerFunc fn, loggerFuncf fnf, buf *bytes.Buffer, verifyCustom bool, moduleName string) { +func VerifyBasicLogging(t *testing.T, level api.Level, loggerFunc fn, loggerFuncf fnf, buf *bytes.Buffer, verifyCustom bool, moduleName string) { //Call logger func if loggerFunc != nil { @@ -73,10 +74,10 @@ func VerifyBasicLogging(t *testing.T, level loglevel.Level, loggerFunc fn, logge levelName := "print" if verifyCustom { - levelName = loglevel.ParseString(level) + levelName = metadata.ParseString(level) regex = fmt.Sprintf(customLevelOutputExpectedRegex, moduleName) } else if level > 0 && !verifyCustom { - levelName = loglevel.ParseString(level) + levelName = metadata.ParseString(level) opts := getLoggerOpts(moduleName, level) if opts.callerInfoEnabled { //with caller info @@ -90,8 +91,8 @@ func VerifyBasicLogging(t *testing.T, level loglevel.Level, loggerFunc fn, logge } match, err := regexp.MatchString(regex, buf.String()) - utils.VerifyEmpty(t, err, "error while matching regex with logoutput wasnt expected") - utils.VerifyTrue(t, match, "%s logger isn't producing output as expected, \n logoutput:%s\n regex: %s", levelName, buf.String(), regex) + assert.Empty(t, err, "error while matching regex with logoutput wasnt expected") + assert.True(t, match, "%s logger isn't producing output as expected, \n logoutput:%s\n regex: %s", levelName, buf.String(), regex) //Reset output buffer, for next use buf.Reset() diff --git a/pkg/logging/testutils/testutils.go b/pkg/logging/testutils/testutils.go deleted file mode 100644 index 4ed4f0691f..0000000000 --- a/pkg/logging/testutils/testutils.go +++ /dev/null @@ -1,54 +0,0 @@ -/* -Copyright SecureKey Technologies Inc. All Rights Reserved. - -SPDX-License-Identifier: Apache-2.0 -*/ - -package testutils - -import ( - "testing" -) - -//VerifyTrue verifies if boolean input is true, if false then fails test -func VerifyTrue(t *testing.T, input bool, msgAndArgs ...interface{}) { - if !input { - failTest(t, msgAndArgs...) - } -} - -//VerifyFalse verifies if boolean input is false, if true then fails test -func VerifyFalse(t *testing.T, input bool, msgAndArgs ...interface{}) { - if input { - failTest(t, msgAndArgs...) - } -} - -//VerifyEmpty Verifies if input is empty, fails test if not empty -func VerifyEmpty(t *testing.T, in interface{}, msgAndArgs ...interface{}) { - if in == nil { - return - } else if in == "" { - return - } - failTest(t, msgAndArgs...) -} - -//VerifyNotEmpty Verifies if input is not empty, fails test if empty -func VerifyNotEmpty(t *testing.T, in interface{}, msgAndArgs ...interface{}) { - if in != nil { - return - } else if in != "" { - return - } - failTest(t, msgAndArgs...) -} - -func failTest(t *testing.T, msgAndArgs ...interface{}) { - if len(msgAndArgs) == 1 { - t.Fatal(msgAndArgs[0]) - } - if len(msgAndArgs) > 1 { - t.Fatalf(msgAndArgs[0].(string), msgAndArgs[1:]...) - } -} diff --git a/scripts/third_party_pins/fabric/patches/0001-logbridge.patch b/scripts/third_party_pins/fabric/patches/0001-logbridge.patch index 3ca875fab4..4ba998f040 100644 --- a/scripts/third_party_pins/fabric/patches/0001-logbridge.patch +++ b/scripts/third_party_pins/fabric/patches/0001-logbridge.patch @@ -8,8 +8,8 @@ SPDX-License-Identifier: Apache-2.0 Signed-off-by: Troy Ronda --- - sdkpatch/logbridge/logbridge.go | 52 +++++++++++++++++++++++++++++++++++++++++++ - 1 file changed, 52 insertions(+) + sdkpatch/logbridge/logbridge.go | 51 +++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 51 insertions(+) create mode 100644 sdkpatch/logbridge/logbridge.go diff --git a/sdkpatch/logbridge/logbridge.go b/sdkpatch/logbridge/logbridge.go @@ -17,7 +17,7 @@ new file mode 100644 index 00000000..fdeb3a4f --- /dev/null +++ b/sdkpatch/logbridge/logbridge.go -@@ -0,0 +1,52 @@ +@@ -0,0 +1,51 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + @@ -28,12 +28,11 @@ index 00000000..fdeb3a4f + +import ( + "github.com/hyperledger/fabric-sdk-go/pkg/logging" -+ "github.com/hyperledger/fabric-sdk-go/pkg/logging/loglevel" +) + +// Log levels (from fabric-sdk-go/pkg/logging/level.go). +const ( -+ CRITICAL loglevel.Level = iota ++ CRITICAL logging.Level = iota + ERROR + WARNING + INFO @@ -67,7 +66,7 @@ index 00000000..fdeb3a4f +} + +// IsEnabledFor bridges calls to the Go SDK logger's IsEnabledFor. -+func (l *Logger) IsEnabledFor(level loglevel.Level) bool { ++func (l *Logger) IsEnabledFor(level logging.Level) bool { + return logging.IsEnabledFor(l.module, level) +} --