Skip to content

Commit 1da687c

Browse files
committed
move @thebentern spiffy logging so it is shared with !ble log sources
1 parent 42236f2 commit 1da687c

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

meshtastic/ble_interface.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from threading import Thread
99
from typing import Optional
1010

11-
import print_color # type: ignore[import-untyped]
1211
from bleak import BleakClient, BleakScanner, BLEDevice
1312
from bleak.exc import BleakDBusError, BleakError
1413

@@ -82,16 +81,7 @@ def from_num_handler(self, _, b): # pylint: disable=C0116
8281

8382
async def log_radio_handler(self, _, b): # pylint: disable=C0116
8483
log_radio = b.decode("utf-8").replace("\n", "")
85-
if log_radio.startswith("DEBUG"):
86-
print_color.print(log_radio, color="cyan", end=None)
87-
elif log_radio.startswith("INFO"):
88-
print_color.print(log_radio, color="white", end=None)
89-
elif log_radio.startswith("WARN"):
90-
print_color.print(log_radio, color="yellow", end=None)
91-
elif log_radio.startswith("ERROR"):
92-
print_color.print(log_radio, color="red", end=None)
93-
else:
94-
print_color.print(log_radio, end=None)
84+
self._handleLogLine(log_radio)
9585

9686
@staticmethod
9787
def scan() -> list[BLEDevice]:

meshtastic/mesh_interface.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import google.protobuf.json_format
1717
from pubsub import pub # type: ignore[import-untyped]
1818
from tabulate import tabulate
19+
import print_color # type: ignore[import-untyped]
1920

2021
import meshtastic.node
2122

@@ -143,8 +144,21 @@ def __exit__(self, exc_type, exc_value, traceback):
143144

144145
@staticmethod
145146
def _printLogLine(line, interface):
146-
"""Print a line of log output"""
147-
interface.debugOut.write(line + "\n")
147+
"""Print a line of log output."""
148+
if interface.debugOut == sys.stdout:
149+
# this isn't quite correct (could cause false positives), but currently our formatting differs between different log representations
150+
if "DEBUG" in line:
151+
print_color.print(line, color="cyan", end=None)
152+
elif "INFO" in line:
153+
print_color.print(line, color="white", end=None)
154+
elif "WARN" in line:
155+
print_color.print(line, color="yellow", end=None)
156+
elif "ERR" in line:
157+
print_color.print(line, color="red", end=None)
158+
else:
159+
print_color.print(line, end=None)
160+
else:
161+
interface.debugOut.write(line + "\n")
148162

149163
def _handleLogLine(self, line: str) -> None:
150164
"""Handle a line of log output from the device."""

0 commit comments

Comments
 (0)