about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-11-19 09:27:58 -0600
committerFrederick Muriuki Muriithi2025-11-19 13:34:32 -0600
commitc039589c7fcc926254f910d94e6043c4e7e0f6d7 (patch)
tree53a2755111ecefd8e17b4f62539bd953f316d4fc
parent960a816f69cb64b86d1a5ab2b3dddf9ef6c636fc (diff)
downloadgn-uploader-c039589c7fcc926254f910d94e6043c4e7e0f6d7.tar.gz
Add function to setup logging for scripts.
-rw-r--r--scripts/cli/logging.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/scripts/cli/logging.py b/scripts/cli/logging.py
new file mode 100644
index 0000000..30ecf17
--- /dev/null
+++ b/scripts/cli/logging.py
@@ -0,0 +1,18 @@
+"""Logging for scripts."""
+import logging
+
+def setup_logging(
+        script_logger: logging.Logger,
+        loglevel: str,
+        modules: tuple[str, ...] = tuple()
+):
+    """Setup module-level loggers to the same log-level as the application."""
+    logging.basicConfig(
+        encoding="utf-8",
+        format=("%(asctime)s — %(filename)s:%(lineno)s — %(levelname)s: "
+                "%(message)s"),
+        level=logging.INFO)
+    script_logger.setLevel(getattr(logging, loglevel.upper()))
+    effective_loglevel = logging.getLevelName(script_logger.getEffectiveLevel())
+    for module in modules:
+        logging.getLogger(module).setLevel(effective_loglevel)