diff options
| author | Frederick Muriuki Muriithi | 2025-11-19 09:27:58 -0600 |
|---|---|---|
| committer | Frederick Muriuki Muriithi | 2025-11-19 13:34:32 -0600 |
| commit | c039589c7fcc926254f910d94e6043c4e7e0f6d7 (patch) | |
| tree | 53a2755111ecefd8e17b4f62539bd953f316d4fc /scripts/cli/logging.py | |
| parent | 960a816f69cb64b86d1a5ab2b3dddf9ef6c636fc (diff) | |
| download | gn-uploader-c039589c7fcc926254f910d94e6043c4e7e0f6d7.tar.gz | |
Add function to setup logging for scripts.
Diffstat (limited to 'scripts/cli/logging.py')
| -rw-r--r-- | scripts/cli/logging.py | 18 |
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) |
