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
+4 -2
View File
@@ -11,6 +11,8 @@ from providers.callsigndata.api_query_callsign_data_provider import (
APIQueryCallsignDataProvider,
)
logger = logging.getLogger(__name__)
class ClublogAPI(APIQueryCallsignDataProvider):
"""Callsign data provider for Clublog's API."""
@@ -25,7 +27,7 @@ class ClublogAPI(APIQueryCallsignDataProvider):
self._callinfo = Callinfo(lookuplib)
else:
provider_config["enabled"] = False
logging.warning(
logger.warning(
"Clublog XML callsign data provider configured but no api key was provided, this has been disabled."
)
@@ -45,6 +47,6 @@ class ClublogAPI(APIQueryCallsignDataProvider):
except Exception:
self.status = "Error"
logging.exception("Exception when looking up data from Clublog API")
logger.exception("Exception when looking up data from Clublog API")
return callsign_data
+5 -3
View File
@@ -10,6 +10,8 @@ from providers.callsigndata.file_download_callsign_data_provider import (
FileDownloadCallsignDataProvider,
)
logger = logging.getLogger(__name__)
class ClublogXML(FileDownloadCallsignDataProvider):
"""Callsign data provider for ClubLog's Country File, which provides basic callsign to DXCC entity mapping."""
@@ -25,7 +27,7 @@ class ClublogXML(FileDownloadCallsignDataProvider):
self._api_key = provider_config.get("api_key", "")
if self._api_key == "":
provider_config["enabled"] = False
logging.warning(
logger.warning(
"Clublog XML callsign data provider configured but no api key was provided, this has been disabled."
)
@@ -55,7 +57,7 @@ class ClublogXML(FileDownloadCallsignDataProvider):
return True
except Exception:
logging.exception("Exception when loading Clublog XML.")
logger.exception("Exception when loading Clublog XML.")
return False
def _perform_new_lookup(self, callsign, lookup_credentials):
@@ -71,6 +73,6 @@ class ClublogXML(FileDownloadCallsignDataProvider):
except Exception:
self.status = "Error"
logging.exception("Exception when looking up data from Clublog XML data")
logger.exception("Exception when looking up data from Clublog XML data")
return callsign_data
+4 -2
View File
@@ -9,6 +9,8 @@ from providers.callsigndata.file_download_callsign_data_provider import (
FileDownloadCallsignDataProvider,
)
logger = logging.getLogger(__name__)
class CountryFiles(FileDownloadCallsignDataProvider):
"""Callsign data provider for Country-files.com, which provides basic callsign to DXCC entity mapping."""
@@ -35,7 +37,7 @@ class CountryFiles(FileDownloadCallsignDataProvider):
return True
except Exception:
logging.exception("Exception when loading Country Files cty.plist.")
logger.exception("Exception when loading Country Files cty.plist.")
return False
def _perform_new_lookup(self, callsign, lookup_credentials):
@@ -51,6 +53,6 @@ class CountryFiles(FileDownloadCallsignDataProvider):
except Exception:
self.status = "Error"
logging.exception("Exception when looking up data from Country file")
logger.exception("Exception when looking up data from Country file")
return callsign_data
@@ -10,6 +10,8 @@ from core.constants import HTTP_HEADERS
from core.url_data_cache import URLDataCache
from providers.callsigndata.callsign_data_provider import CallsignDataProvider
logger = logging.getLogger(__name__)
class FileDownloadCallsignDataProvider(CallsignDataProvider):
"""Generic callsign data provider class for providers that fetch their data from the web by downloading a file."""
@@ -30,7 +32,7 @@ class FileDownloadCallsignDataProvider(CallsignDataProvider):
def start(self):
# Fire off the polling thread. It will poll immediately on startup, then sleep for poll_interval between
# subsequent polls, so start() returns immediately and the application can continue starting.
logging.info(f"Set up query of {self.name} callsign reference data every {self._poll_interval!s} days.")
logger.info(f"Set up query of {self.name} callsign reference data every {self._poll_interval!s} days.")
self._thread = Thread(target=self._run, name=f"FileDownloadCallsignDataProvider-{self.name}")
self._thread.start()
@@ -47,7 +49,7 @@ class FileDownloadCallsignDataProvider(CallsignDataProvider):
try:
# Request the file. Use the data cache (with a TTL of 1 day) here, not as the main mechanism for
# caching, but just so continual restarts of the software during testing don't hammer the servers.
logging.debug(f"Downloading {self.name} callsign reference data...")
logger.debug(f"Downloading {self.name} callsign reference data...")
http_response = self._url_data_cache.get(self._url, headers=HTTP_HEADERS)
# Check response code was good
if http_response.ok:
@@ -60,26 +62,26 @@ class FileDownloadCallsignDataProvider(CallsignDataProvider):
if ok:
self.status = "OK"
self.last_update_time = datetime.now(pytz.UTC)
logging.info(f"Updated callsign reference data from {self.name}")
logger.info(f"Updated callsign reference data from {self.name}")
else:
self.status = "Error"
logging.warning(f"Error updating callsign reference data from {self.name}.")
logger.warning(f"Error updating callsign reference data from {self.name}.")
else:
self.status = "Error"
logging.warning(
logger.warning(
f"HTTP {http_response.status_code} when downloading callsign reference data from {self.name}."
)
except ConnectionError:
self.status = "Error"
logging.warning(f"Connection error when downloading callsign reference data from {self.name}.")
logger.warning(f"Connection error when downloading callsign reference data from {self.name}.")
except (ConnectTimeout, ReadTimeout):
self.status = "Error"
logging.warning(f"Timeout when downloading callsign reference data from {self.name}.")
logger.warning(f"Timeout when downloading callsign reference data from {self.name}.")
except Exception:
self.status = "Error"
logging.exception(f"Exception in callsign reference data provider ({self.name})")
logger.exception(f"Exception in callsign reference data provider ({self.name})")
self._stop_event.wait(timeout=1)
def _handle_file(self, path):
+10 -8
View File
@@ -17,6 +17,8 @@ from providers.callsigndata.api_query_callsign_data_provider import (
APIQueryCallsignDataProvider,
)
logger = logging.getLogger(__name__)
class HamQTH(APIQueryCallsignDataProvider):
"""Callsign data provider for HamQTH."""
@@ -55,10 +57,10 @@ class HamQTH(APIQueryCallsignDataProvider):
session_id = str(dict_data["HamQTH"]["session"]["session_id"])
else:
# Log this failure at debug level only, not our problem if user entered the wrong password.
logging.debug("HamQTH login details incorrect, failed to look up with HamQTH.")
logger.debug("HamQTH login details incorrect, failed to look up with HamQTH.")
return None
except Exception:
logging.error("Exception when getting HamQTH session key")
logger.error("Exception when getting HamQTH session key")
return None
if not session_id:
@@ -71,7 +73,7 @@ class HamQTH(APIQueryCallsignDataProvider):
if home_call != callsign:
calls_to_try.append(home_call)
except ValueError:
logging.debug(f"Could not look up home call for callsign {callsign}")
logger.debug(f"Could not look up home call for callsign {callsign}")
# Try looking up each call using the API
for lookup_call in calls_to_try:
@@ -90,18 +92,18 @@ class HamQTH(APIQueryCallsignDataProvider):
return self.hamqth_response_to_callsign(callsign, data)
elif not response.from_cache:
logging.warning(f"HTTP {response.status_code} looking up callsign {lookup_call} using HamQTH")
logger.warning(f"HTTP {response.status_code} looking up callsign {lookup_call} using HamQTH")
except (KeyError, ValueError):
continue
except ConnectionError:
logging.warning(f"Connection error when looking up callsign {lookup_call} using HamQTH")
logger.warning(f"Connection error when looking up callsign {lookup_call} using HamQTH")
continue
except (ConnectTimeout, ReadTimeout):
logging.warning(f"Timeout when looking up callsign {lookup_call} using HamQTH")
logger.warning(f"Timeout when looking up callsign {lookup_call} using HamQTH")
continue
except Exception:
logging.exception(f"Exception when looking up callsign {lookup_call} using HamQTH")
logger.exception(f"Exception when looking up callsign {lookup_call} using HamQTH")
continue
# Not found in HamQTH; return a Callsign object with no data so we cache that and don't keep retrying
@@ -109,7 +111,7 @@ class HamQTH(APIQueryCallsignDataProvider):
except Exception:
self.status = "Error"
logging.exception("Exception when looking up data from HamQTH")
logger.exception("Exception when looking up data from HamQTH")
# Return None, this won't be cached so we will be asked to query data again for this call next time.
return None
+12 -10
View File
@@ -16,6 +16,8 @@ from providers.callsigndata.api_query_callsign_data_provider import (
APIQueryCallsignDataProvider,
)
logger = logging.getLogger(__name__)
class QRZ(APIQueryCallsignDataProvider):
"""Callsign data provider for QRZ.com."""
@@ -53,10 +55,10 @@ class QRZ(APIQueryCallsignDataProvider):
session_key = str(session["Key"])
else:
# Log this failure at debug level only, not our problem if user entered the wrong password.
logging.debug("QRZ.com login details incorrect, failed to look up with QRZ.")
logger.debug("QRZ.com login details incorrect, failed to look up with QRZ.")
return None
except Exception:
logging.error("Exception when getting QRZ.com session key")
logger.error("Exception when getting QRZ.com session key")
return None
if not session_key:
@@ -69,7 +71,7 @@ class QRZ(APIQueryCallsignDataProvider):
if home_call != callsign:
calls_to_try.append(home_call)
except ValueError:
logging.debug(f"Could not look up home call for callsign {callsign}")
logger.debug(f"Could not look up home call for callsign {callsign}")
# Try looking up each call using the API
for lookup_call in calls_to_try:
@@ -93,25 +95,25 @@ class QRZ(APIQueryCallsignDataProvider):
elif "Session" in qrz_response and "Error" in qrz_response.get("Session"):
# Errors here are normally just "callsign not in database", no need to log that ourselves
# above debug level.
logging.debug(
logger.debug(
f"QRZ returned an error looking up callsign {lookup_call}: {qrz_response.get('Session').get('Error')}"
)
elif not response.from_cache:
logging.warning(f"QRZ returned a malformed response looking up callsign {lookup_call}")
logger.warning(f"QRZ returned a malformed response looking up callsign {lookup_call}")
elif not response.from_cache:
logging.warning(f"HTTP {response.status_code} looking up callsign {lookup_call} using QRZ")
logger.warning(f"HTTP {response.status_code} looking up callsign {lookup_call} using QRZ")
except (KeyError, ValueError):
continue
except ConnectionError:
logging.warning(f"Connection error when looking up callsign {lookup_call} using QRZ")
logger.warning(f"Connection error when looking up callsign {lookup_call} using QRZ")
continue
except (ConnectTimeout, ReadTimeout):
logging.warning(f"Timeout when looking up callsign {lookup_call} using QRZ.")
logger.warning(f"Timeout when looking up callsign {lookup_call} using QRZ.")
continue
except Exception:
logging.exception(f"Exception when looking up callsign {lookup_call} using QRZ")
logger.exception(f"Exception when looking up callsign {lookup_call} using QRZ")
continue
# Not found in QRZ; return a Callsign object with no data so we cache that and don't keep retrying
@@ -119,7 +121,7 @@ class QRZ(APIQueryCallsignDataProvider):
except Exception:
self.status = "Error"
logging.exception("Exception when looking up data from QRZ.com")
logger.exception("Exception when looking up data from QRZ.com")
# Return None, this won't be cached so we will be asked to query data again for this call next time.
return None