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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,15 @@ meshcore = await MeshCore.create_serial("/dev/ttyUSB0", debug=True)

This logs detailed information about commands sent and events received.

meshcore_py does not configure Python's root logger or call `logging.basicConfig()` itself - it only attaches a `NullHandler` so it stays silent by default. To see its logs, configure logging in your own application, e.g.:

```python
import logging

logging.basicConfig(level=logging.INFO)
logging.getLogger("meshcore").setLevel(logging.DEBUG)
```

## Common Examples

### Sending Messages to Contacts
Expand Down
6 changes: 4 additions & 2 deletions src/meshcore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
from .serial_cx import SerialConnection
from .tcp_cx import TCPConnection

# Setup default logger
logging.basicConfig(level=logging.INFO)
# Setup default logger. Libraries must not configure the root logger (that's
# the embedding application's call) - a NullHandler just silences the "no
# handlers found" warning when the app hasn't configured logging at all.
logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())

__all__ = [
"BinaryReqType",
Expand Down
6 changes: 3 additions & 3 deletions src/meshcore/meshcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ def __init__(
self.commands = CommandHandler(default_timeout=default_timeout)
self.commands.set_contact_getter_by_prefix(self.get_contact_by_key_prefix)

# Set up logger
# Set up logger. Only override the level when the caller explicitly
# asked for debug/only_error behavior - otherwise leave whatever
# level the embedding app already configured alone.
if debug:
logger.setLevel(logging.DEBUG)
elif only_error:
logger.setLevel(logging.ERROR)
else:
logger.setLevel(logging.INFO)

# Set up connections
self.commands.set_connection(self.connection_manager)
Expand Down