-
Notifications
You must be signed in to change notification settings - Fork 182
Open
Description
Standardize Logger Names in Core Modules (Phase 1)
Description
The current logging implementation in several py-libp2p
modules uses hardcoded logger names instead of the recommended logging.getLogger(__name__)
pattern. This creates inconsistencies and makes it difficult to control logs on a per-module basis through LIBP2P_DEBUG
.
Root Cause Analysis
- Multiple core modules directly define loggers with static names.
- This prevents users from enabling/disabling logs at a module level.
- Logging configuration is inconsistent across the codebase.
Motivation
- Ensures consistent logging practices across all modules.
- Enables fine-grained logging control via
LIBP2P_DEBUG
. - Improves debugging, maintainability, and adherence to Python logging best practices.
Current Implementation
# Example from libp2p/network/swarm.py
logger = logging.getLogger("libp2p.network.swarm")
Proposed Solution
Replace all hardcoded logger names with __name__
to ensure the logger name matches the module path automatically.
# Updated implementation
logger = logging.getLogger(__name__)
This change has been applied in Phase 1 to the following files:
libp2p/network/swarm.py
libp2p/host/basic_host.py
libp2p/transport/tcp/tcp.py
libp2p/pubsub/floodsub.py
libp2p/pubsub/gossipsub.py
libp2p/pubsub/pubsub.py
libp2p/pubsub/validators.py
Are you planning to do it yourself in a pull request?
Yes — already submitted PR #902.
pacrob
Metadata
Metadata
Assignees
Labels
No labels