aboutsummaryrefslogtreecommitdiff
path: root/scripts/rqtl2/entry.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-10-24 15:54:24 -0500
committerFrederick Muriuki Muriithi2024-10-24 15:56:41 -0500
commita52401e7191850c4a6542da1af5f2b2769312871 (patch)
tree52a9622b2f8461ef4074bd775460b22963ae10a5 /scripts/rqtl2/entry.py
parent80ae9ca56a34ae11c840bd6a7d24fbd9771c0c3e (diff)
downloadgn-uploader-a52401e7191850c4a6542da1af5f2b2769312871.tar.gz
Move logger creation to `build_main` function
Since the module-level loggers are built mostly the same, move the creation of the logger to the more general function to reduce repetition.
Diffstat (limited to 'scripts/rqtl2/entry.py')
-rw-r--r--scripts/rqtl2/entry.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/scripts/rqtl2/entry.py b/scripts/rqtl2/entry.py
index 5c7e7e4..bc4cd9f 100644
--- a/scripts/rqtl2/entry.py
+++ b/scripts/rqtl2/entry.py
@@ -1,5 +1,5 @@
"""Build common script-entry structure."""
-from logging import Logger
+import logging
from typing import Callable
from argparse import Namespace
@@ -12,12 +12,19 @@ from uploader.check_connections import check_db, check_redis
from scripts.redis_logger import setup_redis_logger
-def build_main(args: Namespace,
- run_fn: Callable[[Connection, Namespace], int],
- logger: Logger,
- loglevel: str = "INFO") -> Callable[[],int]:
+def build_main(
+ args: Namespace,
+ run_fn: Callable[[Connection, Namespace, logging.Logger], int],
+ loggername: str
+) -> Callable[[],int]:
"""Build a function to be used as an entry-point for scripts."""
def main():
+ logging.basicConfig(
+ format=(
+ "%(asctime)s - %(levelname)s %(name)s: "
+ "(%(pathname)s: %(lineno)d) %(message)s"),
+ level=args.loglevel)
+ logger = logging.getLogger(loggername)
check_db(args.databaseuri)
check_redis(args.redisuri)
if not args.rqtl2bundle.exists():
@@ -32,7 +39,6 @@ def build_main(args: Namespace,
fqjobid,
f"{fqjobid}:log-messages",
args.redisexpiry))
- logger.setLevel(loglevel)
- return run_fn(dbconn, args)
+ return run_fn(dbconn, args, logger)
return main