Replies: 2 comments 2 replies
-
Issue: Standardize Logger Names in Core Modules (Phase 1)🎯 Good First Issue - Phase 1/3This is the first phase of standardizing logging configuration across py-libp2p. Perfect for new contributors to get familiar with the codebase! 📋 BackgroundThe py-libp2p library has an excellent logging system in LIBP2P_DEBUG=network:DEBUG,pubsub:INFO However, many modules use hardcoded logger names instead of 🎯 GoalUpdate core networking and pubsub modules to use 📂 Files to Update (Phase 1 - 7 files)Network & Host Modules
PubSub Modules
🔧 Step-by-Step Instructions1. Find the Logger DeclarationIn each file, look for a line like: logger = logging.getLogger("some.hardcoded.name") 2. Replace with nameChange it to: logger = logging.getLogger(__name__) 3. Example ChangeBefore: import logging
from libp2p.abc import IHost
logger = logging.getLogger("libp2p.network.swarm")
class Swarm:
# ... rest of the class After: import logging
from libp2p.abc import IHost
logger = logging.getLogger(__name__)
class Swarm:
# ... rest of the class ✅ Testing Your Changes1. Basic TestRun any example to ensure no import errors: cd examples/ping/
python ping.py 2. Test Module-Specific LoggingTest that module-specific logging control works: # Test network module logging
LIBP2P_DEBUG=network:DEBUG python examples/ping/ping.py
# Test pubsub module logging
LIBP2P_DEBUG=pubsub:DEBUG python examples/pubsub/pubsub.py
# Test combined logging
LIBP2P_DEBUG=network:DEBUG,pubsub:INFO python examples/pubsub/pubsub.py You should see debug messages from the specific modules you configured. 3. Verify Logger NamesAdd a temporary test to verify the logger names are correct: import logging
from libp2p.network.swarm import logger as swarm_logger
from libp2p.pubsub.gossipsub import logger as gossip_logger
print(f"Swarm logger name: {swarm_logger.name}") # Should be "libp2p.network.swarm"
print(f"GossipSub logger name: {gossip_logger.name}") # Should be "libp2p.pubsub.gossipsub" 📝 Submission Guidelines1. Commit Message Format
2. PR Description Template## 🎯 Issue
Fixes logging standardization in core modules (Phase 1)
## 📋 Changes
- [x] Updated 7 core modules to use `logging.getLogger(__name__)`
- [x] Tested module-specific logging control works correctly
- [x] Verified no import errors or functionality changes
## 🧪 Testing
- [x] Basic functionality tests pass
- [x] Module-specific logging control verified with LIBP2P_DEBUG
- [x] No breaking changes to existing logging behavior
## 📚 Learning
Brief summary of what you learned about the codebase while working on this. 🤝 Getting HelpQuestions to Ask:
Resources:
🚀 Next StepsIf you complete Phase 1 successfully and want to continue:
🎉 Why This MattersAfter your changes:
Estimated Time: 2-3 hours for a new contributor |
Beta Was this translation helpful? Give feedback.
-
@PankajJaisu I'm back in github |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Logging Analysis Report for py-libp2p
Last review: Sept 3 2025
Executive Summary
This report provides a comprehensive analysis of the logging configuration across the py-libp2p codebase. The library implements a sophisticated logging system but suffers from inconsistent adoption and configuration across modules. Key findings include proper logging in some areas, inconsistent naming patterns in core modules, and completely absent logging in critical security components.
Logging System Architecture
Core Infrastructure
The library features a well-designed logging system located in
libp2p/utils/logging.py
with the following capabilities:LIBP2P_DEBUG
for granular controlQueueHandler
andQueueListener
LIBP2P_DEBUG_FILE
Configuration Format
The system expects loggers to follow the pattern:
libp2p.{module}.{submodule}
and supports configurations like:LIBP2P_DEBUG=DEBUG
(global debug)LIBP2P_DEBUG=identity.identify:DEBUG,transport:INFO
(module-specific)Current State Analysis
✅ Well-Configured Modules
These modules correctly implement logging using
logging.getLogger(__name__)
:Identity & Authentication
libp2p/identity/identify/identify.py
libp2p/identity/identify_push/identify_push.py
Relay Components
libp2p/relay/circuit_v2/dcutr.py
Example Code
examples/doc-examples/multiple_connections_example.py
Test Infrastructure
tests/core/examples/test_examples.py
These modules use hardcoded logger names instead of
__name__
, breaking the hierarchical system:Core Networking
Transport Layer
Stream Multiplexing
Publish-Subscribe System
Peer Discovery
Utility & Support Modules
🚨 Problematic Configurations
Non-Standard Logger Hierarchies
The Kademlia DHT implementation uses completely non-standard logger names:
The PubSub utilities module also uses non-standard naming:
Third-party Logger Names
❌ Missing Logging
Critical security modules completely lack logging configuration:
libp2p/security/noise/transport.py
libp2p/security/secio/transport.py
Impact Assessment
Functional Impact
LIBP2P_DEBUG=module:LEVEL
syntaxkademlia-example.*
) are completely outside the libp2p hierarchyDevelopment Impact
Recommendations
1. Immediate Priority: Standardize Core Modules
Convert all modules to use
logging.getLogger(__name__)
:High Priority Files:
libp2p/network/swarm.py
libp2p/host/basic_host.py
libp2p/transport/tcp/tcp.py
libp2p/stream_muxer/yamux/yamux.py
libp2p/stream_muxer/mplex/mplex.py
libp2p/pubsub/floodsub.py
libp2p/pubsub/gossipsub.py
2. Critical: Fix Kademlia DHT Modules
Replace all
kademlia-example.*
logger names with proper hierarchy:Affected Files:
libp2p/kad_dht/kad_dht.py
libp2p/kad_dht/value_store.py
libp2p/kad_dht/provider_store.py
libp2p/kad_dht/peer_routing.py
libp2p/kad_dht/routing_table.py
libp2p/kad_dht/utils.py
3. Essential: Add Security Module Logging
Implement comprehensive logging in security modules:
Target Files:
libp2p/security/noise/transport.py
libp2p/security/secio/transport.py
4. Cleanup: Fix Remaining Inconsistencies
libp2p/pubsub/utils.py
from"pubsub-example.utils"
to__name__
libp2p/tools/async_service/base.py
5. Documentation Updates
Update documentation to reflect:
Implementation Strategy
Phase 1: Core Infrastructure (Week 1)
LIBP2P_DEBUG
Phase 2: Application Layer (Week 2)
Phase 3: Security & Utilities (Week 3)
Phase 4: Testing & Documentation (Week 4)
Testing Verification
After implementation, verify fixes with:
Conclusion
The py-libp2p logging system has excellent architectural design but suffers from inconsistent implementation across ~50 modules. The most critical issues are:
Addressing these issues will provide:
The fixes are straightforward but require systematic implementation across the codebase. Prioritizing core networking and DHT modules will provide the most immediate benefit.
Beta Was this translation helpful? Give feedback.
All reactions