mirror of
https://github.com/craigerl/aprsd.git
synced 2024-10-18 09:40:16 -04:00
Added color logging of thread names at keepalive
This patch adds logging of the thread name in color during keepalive loop output.
This commit is contained in:
parent
5314856101
commit
5e9f92dfa6
@ -3,6 +3,7 @@ import logging
|
|||||||
import time
|
import time
|
||||||
import tracemalloc
|
import tracemalloc
|
||||||
|
|
||||||
|
from loguru import logger
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
from aprsd import packets, utils
|
from aprsd import packets, utils
|
||||||
@ -14,6 +15,7 @@ from aprsd.threads import APRSDThread, APRSDThreadList
|
|||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
LOG = logging.getLogger("APRSD")
|
LOG = logging.getLogger("APRSD")
|
||||||
|
LOGU = logger
|
||||||
|
|
||||||
|
|
||||||
class KeepAliveThread(APRSDThread):
|
class KeepAliveThread(APRSDThread):
|
||||||
@ -87,7 +89,12 @@ class KeepAliveThread(APRSDThread):
|
|||||||
key = thread["name"]
|
key = thread["name"]
|
||||||
if not alive:
|
if not alive:
|
||||||
LOG.error(f"Thread {thread}")
|
LOG.error(f"Thread {thread}")
|
||||||
LOG.info(f"{key: <15} Alive? {str(alive): <5} {str(age): <20}")
|
|
||||||
|
thread_hex = f"fg {utils.hex_from_name(key)}"
|
||||||
|
t_name = f"<{thread_hex}>{key:<15}</{thread_hex}>"
|
||||||
|
thread_msg = f"{t_name} Alive? {str(alive): <5} {str(age): <20}"
|
||||||
|
LOGU.opt(colors=True).info(thread_msg)
|
||||||
|
# LOG.info(f"{key: <15} Alive? {str(alive): <5} {str(age): <20}")
|
||||||
|
|
||||||
# check the APRS connection
|
# check the APRS connection
|
||||||
cl = client_factory.create()
|
cl = client_factory.create()
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import errno
|
import errno
|
||||||
import functools
|
import functools
|
||||||
|
import math
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
@ -82,6 +83,16 @@ def rgb_from_name(name):
|
|||||||
return red, green, blue
|
return red, green, blue
|
||||||
|
|
||||||
|
|
||||||
|
def hextriplet(colortuple):
|
||||||
|
"""Convert a color tuple to a hex triplet."""
|
||||||
|
return "#" + "".join(f"{i:02X}" for i in colortuple)
|
||||||
|
|
||||||
|
|
||||||
|
def hex_from_name(name):
|
||||||
|
"""Create a hex color from a string."""
|
||||||
|
return hextriplet(rgb_from_name(name))
|
||||||
|
|
||||||
|
|
||||||
def human_size(bytes, units=None):
|
def human_size(bytes, units=None):
|
||||||
"""Returns a human readable string representation of bytes"""
|
"""Returns a human readable string representation of bytes"""
|
||||||
if not units:
|
if not units:
|
||||||
@ -161,3 +172,47 @@ def load_entry_points(group):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Extension {ep.name} of group {group} failed to load with {e}", file=sys.stderr)
|
print(f"Extension {ep.name} of group {group} failed to load with {e}", file=sys.stderr)
|
||||||
print(traceback.format_exc(), file=sys.stderr)
|
print(traceback.format_exc(), file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
|
def calculate_initial_compass_bearing(start, end):
|
||||||
|
if (type(start) != tuple) or (type(end) != tuple):
|
||||||
|
raise TypeError("Only tuples are supported as arguments")
|
||||||
|
|
||||||
|
lat1 = math.radians(float(start[0]))
|
||||||
|
lat2 = math.radians(float(end[0]))
|
||||||
|
|
||||||
|
diffLong = math.radians(float(end[1]) - float(start[1]))
|
||||||
|
|
||||||
|
x = math.sin(diffLong) * math.cos(lat2)
|
||||||
|
y = math.cos(lat1) * math.sin(lat2) - (
|
||||||
|
math.sin(lat1)
|
||||||
|
* math.cos(lat2) * math.cos(diffLong)
|
||||||
|
)
|
||||||
|
|
||||||
|
initial_bearing = math.atan2(x, y)
|
||||||
|
|
||||||
|
# Now we have the initial bearing but math.atan2 return values
|
||||||
|
# from -180° to + 180° which is not what we want for a compass bearing
|
||||||
|
# The solution is to normalize the initial bearing as shown below
|
||||||
|
initial_bearing = math.degrees(initial_bearing)
|
||||||
|
compass_bearing = (initial_bearing + 360) % 360
|
||||||
|
|
||||||
|
return compass_bearing
|
||||||
|
|
||||||
|
|
||||||
|
def degrees_to_cardinal(bearing, full_string=False):
|
||||||
|
if full_string:
|
||||||
|
DIRECTIONS = [
|
||||||
|
"North", "North-Northeast", "Northeast", "East-Northeast", "East", "East-Southeast",
|
||||||
|
"Southeast", "South-Southeast", "South", "South-Southwest", "Southwest", "West-Southwest",
|
||||||
|
"West", "West-Northwest", "Northwest", "North-Northwest", "North",
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
DIRECTIONS = [
|
||||||
|
"N", "NNE", "NE", "ENE", "E", "ESE",
|
||||||
|
"SE", "SSE", "S", "SSW", "SW", "WSW",
|
||||||
|
"W", "WNW", "NW", "NNW", "N",
|
||||||
|
]
|
||||||
|
|
||||||
|
cardinal = DIRECTIONS[round(bearing / 22.5)]
|
||||||
|
return cardinal
|
||||||
|
Loading…
Reference in New Issue
Block a user