mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-09-15 18:26:38 +00:00
Merge pull request #102 from joeyleake/fix/58-dont-configure-root-logger
Stop configuring the root logger on import
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -9,9 +9,11 @@ from .packets import BinaryReqType
|
||||
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",
|
||||
|
||||
@@ -46,13 +46,13 @@ class MeshCore:
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user