Replace root logger calls with module-specific loggers

This commit is contained in:
Ian Renton
2026-08-15 08:35:06 +01:00
parent 74bcd9cded
commit dd89ff4af7
64 changed files with 328 additions and 216 deletions
+3 -1
View File
@@ -6,6 +6,8 @@ import pytz
from core.data_store import DATA_STORE
logger = logging.getLogger(__name__)
class CleanupTimer:
"""Provides a timed cleanup of the spot list."""
@@ -63,7 +65,7 @@ class CleanupTimer:
except Exception:
self.status = "Error"
logging.exception("Exception in Cleanup thread")
logger.exception("Exception in Cleanup thread")
self._stop_event.wait(timeout=1)
+4 -2
View File
@@ -4,9 +4,11 @@ import os
import yaml
logger = logging.getLogger(__name__)
# Check you have a config file
if not os.path.isfile("config.yml"):
logging.error(
logger.error(
"Your config file is missing. Ensure you have copied config-example.yml to config.yml and updated it according to your needs."
)
exit()
@@ -14,7 +16,7 @@ if not os.path.isfile("config.yml"):
# Load config
with open("config.yml") as f:
config = yaml.safe_load(f)
logging.info("Loaded config.")
logger.info("Loaded config.")
BASE_URL = config.get("base_url", "http://localhost:8080")
MAX_SPOT_AGE = config.get("max_spot_age_sec", 3600)
+3 -1
View File
@@ -3,6 +3,8 @@ import threading
from core.config import config, create_provider_from_config
logger = logging.getLogger(__name__)
class DataProviders:
"""Global object for storing data providers."""
@@ -33,7 +35,7 @@ class DataProviders:
def start_providers(providers, provider_type):
"""Helper method to activate enabled providers in the list."""
logging.info(f"Starting {provider_type} providers...")
logger.info(f"Starting {provider_type} providers...")
for p in providers:
if p.enabled:
p.start()
+6 -4
View File
@@ -8,6 +8,8 @@ from core.config import MAX_ALERT_AGE, MAX_SPOT_AGE
from core.live_data_cache import LiveDataCache
from data.solar_conditions import SolarConditions
logger = logging.getLogger(__name__)
CACHE_DIR = "./cache/"
@@ -64,7 +66,7 @@ class DataStore:
# of dict in diskcache absolutely destroys performance with unpickling huge dicts, so we have an ugly "SIG:ref"
# syntax for keys to keep it a single level.
self.sigrefs = diskcache.Cache(f"{CACHE_DIR}sigrefs")
logging.info(f"Loaded data for {len(self.sigrefs)} SIG references.")
logger.info(f"Loaded data for {len(self.sigrefs)} SIG references.")
# Standard disk cache for callsign data. This data does have a TTL to trigger an occasional re-lookup.
# Old data *is* better than no data, but we can't have a background thread re-looking-up every callsign
@@ -83,7 +85,7 @@ class DataStore:
self.callsign_data_hamqth,
]:
unique_keys.update(c)
logging.info(f"Loaded data for {len(unique_keys)} callsigns.")
logger.info(f"Loaded data for {len(unique_keys)} callsigns.")
# Special caches for spots and alerts, which have TTL and write snapshots to disk at an interval. We
# specifically load these caches *last* so that any sigref and callsign data is already loaded from disk cache
@@ -94,7 +96,7 @@ class DataStore:
snapshot_dir=f"{CACHE_DIR}spots",
snapshot_interval_sec=self._SPOT_ALERT_SNAPSHOT_INTERVAL_SEC,
)
logging.info(f"Loaded {len(self.spots.keys())} spots from a previous run.")
logger.info(f"Loaded {len(self.spots.keys())} spots from a previous run.")
self.alerts = LiveDataCache(
maxsize=self._MAX_ALERT_COUNT,
@@ -102,7 +104,7 @@ class DataStore:
snapshot_dir=f"{CACHE_DIR}alerts",
snapshot_interval_sec=self._SPOT_ALERT_SNAPSHOT_INTERVAL_SEC,
)
logging.info(f"Loaded {len(self.alerts.keys())} alerts from a previous run.")
logger.info(f"Loaded {len(self.alerts.keys())} alerts from a previous run.")
def regenerate_call_regex_to_dxcc_entity_map(self):
"""DXCC entity data from K0SWE includes a regex which we can use to match a callsign, and determine which DXCC
+3 -1
View File
@@ -7,6 +7,8 @@ from shapely.geometry import Point, Polygon
from core.data_store import DATA_STORE
logger = logging.getLogger(__name__)
TRANSFORMER_OS_GRID_TO_WGS84 = Transformer.from_crs("EPSG:27700", "EPSG:4326")
TRANSFORMER_IRISH_GRID_TO_WGS84 = Transformer.from_crs("EPSG:29903", "EPSG:4326")
TRANSFORMER_CI_UTM_GRID_TO_WGS84 = Transformer.from_crs("+proj=utm +zone=30 +ellps=WGS84", "EPSG:4326")
@@ -172,7 +174,7 @@ def wab_wai_square_to_lat_lon(ref):
elif re.match(r"^W[AV][0-9]{2}$", ref):
return utm_grid_square_to_lat_lon(ref)
else:
logging.warning(f"Invalid WAB/WAI square: {ref}")
logger.warning(f"Invalid WAB/WAI square: {ref}")
return None
+5 -3
View File
@@ -5,6 +5,8 @@ import time
import diskcache
from cachetools import TTLCache
logger = logging.getLogger(__name__)
class LiveDataCache:
"""Cache for spots and alerts. Uses the fast in-memory TTLCache for normal data I/O, including the TTL to enforce
@@ -34,7 +36,7 @@ class LiveDataCache:
try:
callback(value)
except Exception:
logging.exception(f"Listener raised an exception for key {key}")
logger.exception(f"Listener raised an exception for key {key}")
def get(self, key, default=None):
with self._lock:
@@ -70,7 +72,7 @@ class LiveDataCache:
try:
self._disk_cache.set("snapshot", data)
except Exception as e:
logging.exception(f"Failed to write snapshot to {self._snapshot_dir}")
logger.exception(f"Failed to write snapshot to {self._snapshot_dir}")
def _load_snapshot(self):
data = self._disk_cache.get("snapshot")
@@ -83,7 +85,7 @@ class LiveDataCache:
# Only restore entries that would still be within TTL
if now - saved_at < self._ttl:
self._cache[key] = value
logging.info(f"Loaded snapshot from {self._snapshot_dir}")
logger.info(f"Loaded snapshot from {self._snapshot_dir}")
def _start_periodic_snapshot(self, interval):
def loop():
+6 -4
View File
@@ -6,6 +6,8 @@ from core.data_store import DATA_STORE
from core.geo_utils import wab_wai_square_to_lat_lon
from data.sig_ref import SIGRef
logger = logging.getLogger(__name__)
def get_sig_ref_info(sig, ref_id):
"""Look up details of a SIG reference (e.g. POTA park) such as name, lat/lon, and grid. Takes in a sig name and
@@ -14,7 +16,7 @@ def get_sig_ref_info(sig, ref_id):
SIG we are getting data for."""
if sig is None or sig == "" or ref_id is None or ref_id == "":
logging.debug("Failed to look up sig_ref info, sig or ref were not set.")
logger.debug("Failed to look up sig_ref info, sig or ref were not set.")
return None
sig_ref = SIGRef(sig=sig, id=ref_id)
@@ -59,7 +61,7 @@ def get_sig_ref_info(sig, ref_id):
sig_ref.latitude = ll[0]
sig_ref.longitude = ll[1]
except:
logging.warning("Invalid lat/lon received for WAB/WAI reference")
logger.warning("Invalid lat/lon received for WAB/WAI reference")
return sig_ref
elif sig.upper() == "BOTA":
@@ -83,10 +85,10 @@ def get_sig_ref_info(sig, ref_id):
else:
# Maybe a super new reference we don't know about yet, but more likely a typo or a test reference,
# just silently ignore it.
logging.debug(f"{sig} database did not contain data for ref {ref_id}")
logger.debug(f"{sig} database did not contain data for ref {ref_id}")
except Exception:
logging.exception(f"Exception when looking up sig_ref info for {sig} ref {ref_id}")
logger.exception(f"Exception when looking up sig_ref info for {sig} ref {ref_id}")
return sig_ref
+3 -1
View File
@@ -16,6 +16,8 @@ from core.constants import (
from core.data_store import DATA_STORE
from data.callsign import Callsign
logger = logging.getLogger(__name__)
def safe_json_dumps(obj):
"""Safe version of json.dumps that also converts objects to dicts so they can be output, and ignores NaN floats
@@ -47,7 +49,7 @@ def infer_mode_type_from_mode(mode):
return "DATA"
else:
if mode.upper() != "OTHER":
logging.warning(f"Found an unrecognised mode: {mode}. Developer should categorise this.")
logger.warning(f"Found an unrecognised mode: {mode}. Developer should categorise this.")
return None