Skip to content
Open
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
2 changes: 1 addition & 1 deletion examples/pubsub/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
level=logging.INFO, # Set default to DEBUG for more verbose output
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
logger = logging.getLogger("pubsub-demo")
logger = logging.getLogger(__name__)
CHAT_TOPIC = "pubsub-chat"
GOSSIPSUB_PROTOCOL_ID = TProtocol("/meshsub/1.0.0")

Expand Down
2 changes: 1 addition & 1 deletion libp2p/host/basic_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
# telling it to listen on the given listen addresses.


logger = logging.getLogger("libp2p.network.basic_host")
logger = logging.getLogger(__name__)
DEFAULT_NEGOTIATE_TIMEOUT = 5


Expand Down
3 changes: 1 addition & 2 deletions libp2p/network/swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
SwarmException,
)

logger = logging.getLogger("libp2p.network.swarm")

logger = logging.getLogger(__name__)

def create_default_stream_handler(network: INetworkService) -> StreamHandlerFn:
async def stream_handler(stream: INetStream) -> None:
Expand Down
3 changes: 1 addition & 2 deletions libp2p/pubsub/floodsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@

PROTOCOL_ID = TProtocol("/floodsub/1.0.0")

logger = logging.getLogger("libp2p.pubsub.floodsub")

logger = logging.getLogger(__name__)

class FloodSub(IPubsubRouter):
protocols: list[TProtocol]
Expand Down
2 changes: 1 addition & 1 deletion libp2p/pubsub/gossipsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
PROTOCOL_ID = TProtocol("/meshsub/1.0.0")
PROTOCOL_ID_V11 = TProtocol("/meshsub/1.1.0")

logger = logging.getLogger("libp2p.pubsub.gossipsub")
logger = logging.getLogger(__name__)


class GossipSub(IPubsubRouter, Service):
Expand Down
2 changes: 1 addition & 1 deletion libp2p/pubsub/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
rpc_pb2,
)

logger = logging.getLogger("libp2p.pubsub")
logger = logging.getLogger(__name__)

PUBSUB_SIGNING_PREFIX = "libp2p-pubsub:"

Expand Down
3 changes: 1 addition & 2 deletions libp2p/transport/tcp/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
OpenConnectionError,
)

logger = logging.getLogger("libp2p.transport.tcp")

logger = logging.getLogger(__name__)

class TCPListener(IListener):
listeners: list[trio.SocketListener]
Expand Down
52 changes: 52 additions & 0 deletions tests/core/test_libp2p/test_logger_names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import logging
from libp2p.network import swarm
from libp2p.pubsub import gossipsub


def test_logger_names():
"""Test that logger names use __name__ correctly."""
assert swarm.logger.name == "libp2p.network.swarm"
assert gossipsub.logger.name == "libp2p.pubsub.gossipsub"


def test_loggers_exist_and_callable():
"""Test that loggers exist and can be called without errors."""
# Test that loggers are Logger instances
assert isinstance(swarm.logger, logging.Logger)
assert isinstance(gossipsub.logger, logging.Logger)

assert hasattr(swarm.logger, 'debug')
assert hasattr(swarm.logger, 'info')
assert hasattr(swarm.logger, 'warning')
assert hasattr(swarm.logger, 'error')

assert callable(swarm.logger.debug)
assert callable(swarm.logger.info)


try:
swarm.logger.info("Test info message")
gossipsub.logger.info("Test gossipsub message")
assert True
except Exception as e:
assert False, f"Logger calls failed with exception: {e}"


def manual_logger_verification():
"""Run this manually to verify loggers work with LIBP2P_DEBUG."""
print("=== Manual Logger Verification ===")
print(f"Swarm logger name: {swarm.logger.name}")
print(f"GossipSub logger name: {gossipsub.logger.name}")

print("\nTesting different log levels:")
swarm.logger.debug("This is a debug message from swarm")
swarm.logger.info("This is an info message from swarm")
gossipsub.logger.debug("This is a debug message from gossipsub")
gossipsub.logger.info("This is an info message from gossipsub")

print("\nTo test LIBP2P_DEBUG functionality, run:")
print("LIBP2P_DEBUG=network:DEBUG python -c 'from tests.core.test_libp2p.test_logger_names import manual_logger_verification; manual_logger_verification()'")


if __name__ == "__main__":
manual_logger_verification()
Loading