Skip to content

Remove redundant logger.IsEnabledFor(zapcore.DebugLevel) #855 #1074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions token/services/identity/deserializer/typed.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/hyperledger-labs/fabric-token-sdk/token/services/identity"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/logging"
"github.com/pkg/errors"
"go.uber.org/zap/zapcore"
)

var logger = logging.MustGetLogger("token-sdk.services.identity.deserializer")
Expand Down Expand Up @@ -58,9 +57,7 @@ func (v *TypedVerifierDeserializerMultiplex) DeserializeVerifier(id driver.Ident
if !ok {
return nil, errors.Errorf("no deserializer found for [%s]", si.Type)
}
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("Deserializing [%s] with type [%s]", id, si.Type)
}
logger.Debugf("Deserializing [%s] with type [%s]", id, si.Type)
var errs []error
for _, deserializer := range dess {
verifier, err := deserializer.DeserializeVerifier(si.Type, si.Identity)
Expand Down
16 changes: 4 additions & 12 deletions token/services/identity/idemix/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ func (c *IdentityCache) Identity(auditInfo []byte) (driver.Identity, []byte, err
}
})

if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("fetching identity from cache...")
}
logger.Debugf("fetching identity from cache...")

return c.fetchIdentityFromCache()
}
Expand Down Expand Up @@ -100,16 +98,12 @@ func (c *IdentityCache) fetchIdentityFromCache() (driver.Identity, []byte, error
}

func (c *IdentityCache) fetchIdentityFromBackend(auditInfo []byte) (driver.Identity, []byte, error) {
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("fetching identity from backend")
}
logger.Debugf("fetching identity from backend")
id, audit, err := c.backed(auditInfo)
if err != nil {
return nil, nil, err
}
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("fetch identity from backend done [%s][%d]", id, len(audit))
}
logger.Debugf("fetch identity from backend done [%s][%d]", id, len(audit))

return id, audit, nil
}
Expand All @@ -122,9 +116,7 @@ func (c *IdentityCache) provisionIdentities() {
logger.Errorf("failed to provision identity [%s]", err)
continue
}
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("generated new idemix identity [%d]", count)
}
logger.Debugf("generated new idemix identity [%d]", count)
c.cache <- identityCacheEntry{Identity: id, Audit: audit}
}
}
8 changes: 2 additions & 6 deletions token/services/identity/membership/lm.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ func (l *LocalMembership) GetIdentifier(id driver.Identity) (string, error) {
defer l.localIdentitiesMutex.RUnlock()

for _, label := range []string{string(id), id.String()} {
if l.logger.IsEnabledFor(zapcore.DebugLevel) {
l.logger.Debugf("get local identity by label [%s]", label)
}
l.logger.Debugf("get local identity by label [%s]", label)
r := l.getLocalIdentity(label)
if r == nil {
if l.logger.IsEnabledFor(zapcore.DebugLevel) {
Expand Down Expand Up @@ -451,9 +449,7 @@ func (l *LocalMembership) addLocalIdentity(config *driver.IdentityConfiguration,

// if the keyManager is not anonymous
if !keyManager.Anonymous() {
if l.logger.IsEnabledFor(zapcore.DebugLevel) {
l.logger.Debugf("adding identity mapping for [%s]", identity)
}
l.logger.Debugf("adding identity mapping for [%s]", identity)
l.localIdentitiesByIdentity[identity.String()] = localIdentity
if l.binderService != nil {
if err := l.binderService.Bind(l.defaultNetworkIdentity, identity, false); err != nil {
Expand Down
12 changes: 3 additions & 9 deletions token/services/identity/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ func (p *Provider) IsMe(identity driver.Identity) bool {
}

func (p *Provider) RegisterRecipientIdentity(id driver.Identity) error {
if p.Logger.IsEnabledFor(zapcore.DebugLevel) {
p.Logger.Debugf("Registering identity [%s]", id)
}
p.Logger.Debugf("Registering identity [%s]", id)
p.isMeCacheLock.Lock()
p.isMeCache[id.String()] = false
p.isMeCacheLock.Unlock()
Expand Down Expand Up @@ -179,9 +177,7 @@ func (p *Provider) GetRevocationHandler(identity driver.Identity, auditInfo []by

func (p *Provider) Bind(longTerm driver.Identity, ephemeral driver.Identity, copyAll bool) error {
if copyAll {
if p.Logger.IsEnabledFor(zapcore.DebugLevel) {
p.Logger.Debugf("Binding ephemeral identity [%s] longTerm identity [%s]", ephemeral, longTerm)
}
p.Logger.Debugf("Binding ephemeral identity [%s] longTerm identity [%s]", ephemeral, longTerm)
setSV := true
signer, err := p.GetSigner(longTerm)
if err != nil {
Expand All @@ -201,9 +197,7 @@ func (p *Provider) Bind(longTerm driver.Identity, ephemeral driver.Identity, cop
setAI := true
auditInfo, err := p.GetAuditInfo(longTerm)
if err != nil {
if p.Logger.IsEnabledFor(zapcore.DebugLevel) {
p.Logger.Debugf("failed getting audit info for [%s][%s]", longTerm, err)
}
p.Logger.Debugf("failed getting audit info for [%s][%s]", longTerm, err)
setAI = false
}

Expand Down
13 changes: 3 additions & 10 deletions token/services/identity/sig/deserializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
idriver "github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/driver"
"github.com/pkg/errors"
"go.uber.org/zap/zapcore"
)

type MultiplexDeserializer struct {
Expand Down Expand Up @@ -63,20 +62,14 @@ func deserialize[V any](copyDeserial []idriver.Deserializer, extractor func(idri
var errs []error

for _, des := range copyDeserial {
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("trying signer deserialization with [%s]", des)
}
logger.Debugf("trying signer deserialization with [%s]", des)
v, err := extractor(des)
if err == nil {
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("trying signer deserialization with [%s] succeeded", des)
}
logger.Debugf("trying signer deserialization with [%s] succeeded", des)
return v, nil
}

if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("trying signer deserialization with [%s] failed [%s]", des, err)
}
logger.Debugf("trying signer deserialization with [%s] failed [%s]", des, err)
errs = append(errs, err)
}

Expand Down
24 changes: 6 additions & 18 deletions token/services/identity/sig/sigservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,35 +193,27 @@ func (o *Service) AreMe(identities ...driver.Identity) []string {
}

func (o *Service) IsMe(identity driver.Identity) bool {
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("is me [%s]?", identity)
}
logger.Debugf("is me [%s]?", identity)
idHash := identity.UniqueID()

// check local cache
o.sync.RLock()
_, ok := o.signers[idHash]
o.sync.RUnlock()
if ok {
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("is me [%s]? yes, from cache", identity)
}
logger.Debugf("is me [%s]? yes, from cache", identity)
return true
}

// check storage
if o.storage != nil {
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("is me [%s]? ask the storage", identity)
}
logger.Debugf("is me [%s]? ask the storage", identity)
exists, err := o.storage.SignerInfoExists(identity)
if err != nil {
logger.Errorf("failed checking if a signer exists [%s]", err)
}
if exists {
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("is me [%s]? yes, from storage", identity)
}
logger.Debugf("is me [%s]? yes, from storage", identity)
return true
}
}
Expand All @@ -231,9 +223,7 @@ func (o *Service) IsMe(identity driver.Identity) bool {

func (o *Service) GetSigner(identity driver.Identity) (driver.Signer, error) {
idHash := identity.UniqueID()
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("get signer for [%s]", idHash)
}
logger.Debugf("get signer for [%s]", idHash)
// check the cache
o.sync.RLock()
entry, ok := o.signers[idHash]
Expand All @@ -256,9 +246,7 @@ func (o *Service) getSigner(identity driver.Identity, idHash string) (driver.Sig
return entry.Signer, nil
}

if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("signer for [%s] not found, try to deserialize", idHash)
}
logger.Debugf("signer for [%s] not found, try to deserialize", idHash)
// ask the deserializer
signer, err := o.deserializeSigner(identity)
if err != nil {
Expand Down
17 changes: 4 additions & 13 deletions token/services/identity/wallet/db/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
idriver "github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/driver"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/logging"
"github.com/pkg/errors"
"go.uber.org/zap/zapcore"
)

// WalletRegistry manages wallets whose long-term identities have a given role.
Expand Down Expand Up @@ -75,9 +74,7 @@ func (r *WalletRegistry) Lookup(id driver.WalletLookupID) (driver.Wallet, idrive
return nil, nil, "", errors.WithMessagef(err, "failed to lookup wallet [%s]", id)
}
}
if r.Logger.IsEnabledFor(zapcore.DebugLevel) {
r.Logger.Debugf("looked-up identifier [%s:%s]", identity, toString(walletID))
}
r.Logger.Debugf("looked-up identifier [%s:%s]", identity, logging.WalletID(walletID))
wID := walletID
walletEntry, ok := r.Wallets[wID]
if ok {
Expand All @@ -103,9 +100,7 @@ func (r *WalletRegistry) Lookup(id driver.WalletLookupID) (driver.Wallet, idrive
walletIdentifiers = append(walletIdentifiers, passedWalletID)
}

if r.Logger.IsEnabledFor(zapcore.DebugLevel) {
r.Logger.Debugf("no wallet found for [%s] at [%s]", passedIdentity, toString(wID))
}
r.Logger.Debugf("no wallet found for [%s] at [%s]", passedIdentity, logging.WalletID(wID))
if len(identity) != 0 {
identityWID, err := r.GetWalletID(identity)
r.Logger.Debugf("wallet for identity [%s] -> [%s:%s]", identity, identityWID, err)
Expand All @@ -127,14 +122,10 @@ func (r *WalletRegistry) Lookup(id driver.WalletLookupID) (driver.Wallet, idrive
var idInfo idriver.IdentityInfo
idInfo, err = r.Role.GetIdentityInfo(id)
if err == nil {
if r.Logger.IsEnabledFor(zapcore.DebugLevel) {
r.Logger.Debugf("identity info found at [%s]", toString(id))
}
r.Logger.Debugf("identity info found at [%s]", logging.WalletID(id))
return nil, idInfo, id, nil
} else {
if r.Logger.IsEnabledFor(zapcore.DebugLevel) {
r.Logger.Debugf("identity info not found at [%s]", toString(id))
}
r.Logger.Debugf("identity info not found at [%s]", logging.WalletID(id))
}
}
return nil, nil, "", errors.Errorf("failed to get wallet info for [%s:%v]", toString(walletID), walletIdentifiers)
Expand Down
27 changes: 27 additions & 0 deletions token/services/logging/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Copyright IBM Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/
package logging

import (
"fmt"
"strings"

"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/hash"
)

func WalletID(id string) fmt.Stringer {
return walletID(id)
}

type walletID string

func (w walletID) String() string {
s := string(w)
if len(s) <= 20 {
return strings.ToValidUTF8(s, "X")
}
return fmt.Sprintf("%s~%s", strings.ToValidUTF8(s[:20], "X"), hash.Hashable(s).String())
}
2 changes: 1 addition & 1 deletion token/services/network/orion/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (r *BroadcastResponderView) broadcast(context view.Context, sm *SessionMana
return nil, "", errors.Wrap(err, "failed to unmarshal envelope")
}
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("commit envelope... [%s][%s]", env.TxID(), env.String())
logger.Debugf("commit envelope... [%s][%s]", env.TxID(), env)
}
if err := sm.Orion.TransactionManager().CommitEnvelope(oSession, env); err != nil {
return nil, env.TxID(), err
Expand Down
12 changes: 3 additions & 9 deletions token/services/network/orion/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,16 @@ func (r *RWSetProcessor) tokenRequest(ctx context.Context, tx orion.ProcessTrans
}
trRaw, err := r.GetTokenRequest(tms, txID)
if err != nil {
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("transaction [%s], failed getting token request [%s]", txID, err)
}
logger.Debugf("transaction [%s], failed getting token request [%s]", txID, err)
return errors.WithMessagef(err, "failed to get token request for [%s]", txID)
}
if len(trRaw) == 0 {
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("transaction [%s], no token request found, skip it", txID)
}
logger.Debugf("transaction [%s], no token request found, skip it", txID)
return nil
}
request, err := tms.NewFullRequestFromBytes(trRaw)
if err != nil {
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("transaction [%s], failed getting zkat state from transient map [%s]", txID, err)
}
logger.Debugf("transaction [%s], failed getting zkat state from transient map [%s]", txID, err)
return err
}
if request.Metadata == nil {
Expand Down
9 changes: 2 additions & 7 deletions token/services/nfttx/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx"
token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
"github.com/pkg/errors"
"go.uber.org/zap/zapcore"
)

var logger = logging.MustGetLogger("token-sdk.nfttx")
Expand Down Expand Up @@ -53,9 +52,7 @@ func Wrap(tx *ttx.Transaction) *Transaction {
}

func ReceiveTransaction(context view.Context) (*Transaction, error) {
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("receive a new transaction...")
}
logger.Debugf("receive a new transaction...")

txBoxed, err := context.RunView(ttx.NewReceiveTransactionView(), view.WithSameContext())
if err != nil {
Expand All @@ -66,9 +63,7 @@ func ReceiveTransaction(context view.Context) (*Transaction, error) {
if !ok {
return nil, errors.Errorf("received transaction of wrong type [%T]", cctx)
}
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("received transaction with id [%s]", cctx.ID())
}
logger.Debugf("received transaction with id [%s]", cctx.ID())
// Check that the transaction is valid
if err := cctx.IsValid(); err != nil {
return nil, errors.WithMessagef(err, "invalid transaction %s", cctx.ID())
Expand Down
Loading