mirror of
https://github.com/meshtastic/python.git
synced 2026-02-16 02:41:15 -05:00
move @thebentern spiffy logging so it is shared with !ble log sources
This commit is contained in:
@@ -8,7 +8,6 @@ import time
|
||||
from threading import Thread
|
||||
from typing import Optional
|
||||
|
||||
import print_color # type: ignore[import-untyped]
|
||||
from bleak import BleakClient, BleakScanner, BLEDevice
|
||||
from bleak.exc import BleakDBusError, BleakError
|
||||
|
||||
@@ -82,16 +81,7 @@ class BLEInterface(MeshInterface):
|
||||
|
||||
async def log_radio_handler(self, _, b): # pylint: disable=C0116
|
||||
log_radio = b.decode("utf-8").replace("\n", "")
|
||||
if log_radio.startswith("DEBUG"):
|
||||
print_color.print(log_radio, color="cyan", end=None)
|
||||
elif log_radio.startswith("INFO"):
|
||||
print_color.print(log_radio, color="white", end=None)
|
||||
elif log_radio.startswith("WARN"):
|
||||
print_color.print(log_radio, color="yellow", end=None)
|
||||
elif log_radio.startswith("ERROR"):
|
||||
print_color.print(log_radio, color="red", end=None)
|
||||
else:
|
||||
print_color.print(log_radio, end=None)
|
||||
self._handleLogLine(log_radio)
|
||||
|
||||
@staticmethod
|
||||
def scan() -> list[BLEDevice]:
|
||||
|
||||
@@ -16,6 +16,7 @@ from typing import Any, Callable, Dict, List, Optional, Union
|
||||
import google.protobuf.json_format
|
||||
from pubsub import pub # type: ignore[import-untyped]
|
||||
from tabulate import tabulate
|
||||
import print_color # type: ignore[import-untyped]
|
||||
|
||||
import meshtastic.node
|
||||
|
||||
@@ -143,8 +144,21 @@ class MeshInterface: # pylint: disable=R0902
|
||||
|
||||
@staticmethod
|
||||
def _printLogLine(line, interface):
|
||||
"""Print a line of log output"""
|
||||
interface.debugOut.write(line + "\n")
|
||||
"""Print a line of log output."""
|
||||
if interface.debugOut == sys.stdout:
|
||||
# this isn't quite correct (could cause false positives), but currently our formatting differs between different log representations
|
||||
if "DEBUG" in line:
|
||||
print_color.print(line, color="cyan", end=None)
|
||||
elif "INFO" in line:
|
||||
print_color.print(line, color="white", end=None)
|
||||
elif "WARN" in line:
|
||||
print_color.print(line, color="yellow", end=None)
|
||||
elif "ERR" in line:
|
||||
print_color.print(line, color="red", end=None)
|
||||
else:
|
||||
print_color.print(line, end=None)
|
||||
else:
|
||||
interface.debugOut.write(line + "\n")
|
||||
|
||||
def _handleLogLine(self, line: str) -> None:
|
||||
"""Handle a line of log output from the device."""
|
||||
|
||||
Reference in New Issue
Block a user