fix: standardize logger names in core modules (phase 1) #902
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
Fix logging standardization in core modules (Phase 1)
Changes
logging.getLogger(__name__)
Testing
1. Unit Tests
Added comprehensive unit tests to verify logger functionality:
Results:
test_logger_names
: Verified all logger names are correcttest_loggers_exist_and_callable
: Confirmed loggers work without errors2. Module-Specific Logging Control
Network Module (Ping Example)
Observed logs:
libp2p.network.swarm
logger correctly outputs debug messagesPubSub Module Example
Observed logs:
libp2p.pubsub.gossipsub
logger correctly outputs debug messagesCombined Module Logging
3. Logger Name Verification
Output:
4. Basic Functionality Test
cd examples/ping/ python ping.py
Files Modified
Network & Host Modules
libp2p/network/swarm.py
:logging.getLogger("libp2p.network.swarm")
→logging.getLogger(__name__)
libp2p/host/basic_host.py
:logging.getLogger("libp2p.network.basic_host")
→logging.getLogger(__name__)
libp2p/transport/tcp/tcp.py
:logging.getLogger("libp2p.transport.tcp")
→logging.getLogger(__name__)
PubSub Modules
libp2p/pubsub/floodsub.py
:logging.getLogger("libp2p.pubsub.floodsub")
→logging.getLogger(__name__)
libp2p/pubsub/gossipsub.py
:logging.getLogger("libp2p.pubsub.gossipsub")
→logging.getLogger(__name__)
libp2p/pubsub/pubsub.py
:logging.getLogger("libp2p.pubsub")
→logging.getLogger(__name__)
libp2p/pubsub/validators.py
:logging.getLogger("libp2p.pubsub")
→logging.getLogger(__name__)
Verification Checklist
logging.getLogger(__name__)
LIBP2P_DEBUG
Learning
Working on this issue provided valuable insights into:
libp2p/utils/logging.py
enables module-specific control viaLIBP2P_DEBUG
__name__
: Automatic module path detection eliminates hardcoded strings and ensures consistencyImpact
After these changes, developers now have:
LIBP2P_DEBUG=network:DEBUG,pubsub:INFO
References