From b25daf907e55b720901b75fefca5a723511eee2a Mon Sep 17 00:00:00 2001 From: ric-evans Date: Mon, 28 Oct 2024 16:55:51 -0500 Subject: [PATCH] fix loggers --- skymap_scanner/client/reco_icetray.py | 7 ++++++- skymap_scanner/config.py | 26 ++------------------------ skymap_scanner/server/__init__.py | 10 ++++++---- skymap_scanner/server/start_scan.py | 11 ++++++++++- 4 files changed, 24 insertions(+), 30 deletions(-) diff --git a/skymap_scanner/client/reco_icetray.py b/skymap_scanner/client/reco_icetray.py index 9e8ad3ea3..3fd8094dd 100644 --- a/skymap_scanner/client/reco_icetray.py +++ b/skymap_scanner/client/reco_icetray.py @@ -259,7 +259,12 @@ def main() -> None: ) args = parser.parse_args() - cfg.configure_loggers() + logging_tools.set_level( + os.getenv("SKYSCAN_LOG", cfg.LOG_LEVEL_DEFAULT), # type: ignore[arg-type] + first_party_loggers=__name__.split(".", maxsplit=1)[0], + third_party_level=os.getenv("SKYSCAN_LOG", cfg.LOG_THIRD_PARTY_LEVEL_DEFAULT), # type: ignore[arg-type] + formatter=logging_tools.WIPACDevToolsFormatter(), + ) logging_tools.log_argparse_args(args, logger=LOGGER, level="WARNING") # read startup.json diff --git a/skymap_scanner/config.py b/skymap_scanner/config.py index 8ab7fe3ba..0f0450bf0 100644 --- a/skymap_scanner/config.py +++ b/skymap_scanner/config.py @@ -105,27 +105,5 @@ COLLECTOR_BASE_THRESHOLDS = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0] -# -# logging -# - - -def configure_loggers() -> None: - """Set up loggers with common configurations.""" - hand = logging.StreamHandler() - hand.setFormatter( - logging.Formatter( - "%(asctime)s.%(msecs)03d [%(levelname)8s] %(name)s[%(process)d] %(message)s", - datefmt="%Y-%m-%d %H:%M:%S", - ) - ) - logging.getLogger().addHandler(hand) - logging_tools.set_level( - ENV.SKYSCAN_LOG, # type: ignore[arg-type] - first_party_loggers=__name__.split(".", maxsplit=1)[0], - third_party_level=ENV.SKYSCAN_LOG_THIRD_PARTY, # type: ignore[arg-type] - future_third_parties=["google", "pika"], - specialty_loggers={ - mqclient.queue.LOGGER: ENV.SKYSCAN_MQ_CLIENT_LOG, # type: ignore[dict-item] - }, - ) +LOG_LEVEL_DEFAULT = "INFO" +LOG_THIRD_PARTY_LEVEL_DEFAULT = "WARNING" diff --git a/skymap_scanner/server/__init__.py b/skymap_scanner/server/__init__.py index a75bc177c..1327a378c 100644 --- a/skymap_scanner/server/__init__.py +++ b/skymap_scanner/server/__init__.py @@ -4,6 +4,8 @@ from wipac_dev_tools import from_environment_as_dataclass +from .. import config as cfg + # # Env var constants: set as constants & typecast @@ -69,10 +71,10 @@ class EnvConfig: SKYSCAN_SKYDRIVER_AUTH: str = "" # SkyDriver REST interface auth token # LOGGING VARS - SKYSCAN_LOG: str = "INFO" - SKYSCAN_LOG_THIRD_PARTY: str = "WARNING" - SKYSCAN_EWMS_PILOT_LOG: str = "INFO" - SKYSCAN_MQ_CLIENT_LOG: str = "INFO" + SKYSCAN_LOG: str = cfg.LOG_LEVEL_DEFAULT + SKYSCAN_LOG_THIRD_PARTY: str = cfg.LOG_THIRD_PARTY_LEVEL_DEFAULT + SKYSCAN_EWMS_PILOT_LOG: str = cfg.LOG_LEVEL_DEFAULT + SKYSCAN_MQ_CLIENT_LOG: str = cfg.LOG_LEVEL_DEFAULT # TESTING/DEBUG VARS SKYSCAN_MINI_TEST: bool = False # run minimal variations for testing (mini-scale) diff --git a/skymap_scanner/server/start_scan.py b/skymap_scanner/server/start_scan.py index 00255a367..b60cc9c8d 100644 --- a/skymap_scanner/server/start_scan.py +++ b/skymap_scanner/server/start_scan.py @@ -657,7 +657,16 @@ def _mkdir_if_not_exists(val: str, is_file: bool = False) -> Path: ) args = parser.parse_args() - cfg.configure_loggers() + logging_tools.set_level( + ENV.SKYSCAN_LOG, # type: ignore[arg-type] + first_party_loggers=__name__.split(".", maxsplit=1)[0], + third_party_level=ENV.SKYSCAN_LOG_THIRD_PARTY, # type: ignore[arg-type] + future_third_parties=["google", "pika"], + specialty_loggers={ + mqclient.queue.LOGGER: ENV.SKYSCAN_MQ_CLIENT_LOG, # type: ignore[dict-item] + }, + formatter=logging_tools.WIPACDevToolsFormatter(), + ) logging_tools.log_argparse_args(args, logger=LOGGER, level="WARNING") # nsides -- the class needs the whole list to validate, so this logic can't be outsourced to argparse's `type=`