Skip to content

Commit

Permalink
fix loggers
Browse files Browse the repository at this point in the history
  • Loading branch information
ric-evans committed Oct 28, 2024
1 parent 2407c9d commit b25daf9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 30 deletions.
7 changes: 6 additions & 1 deletion skymap_scanner/client/reco_icetray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 2 additions & 24 deletions skymap_scanner/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
10 changes: 6 additions & 4 deletions skymap_scanner/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion skymap_scanner/server/start_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=`
Expand Down

0 comments on commit b25daf9

Please sign in to comment.