From 1ff27db619491ce49f1ee9cd70573ed31e109181 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Fri, 7 Jun 2024 12:11:20 +0300 Subject: [PATCH] Added error log file Signed-off-by: Dimitris Zlatanidis --- slpkg/configs.py | 1 + slpkg/main.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/slpkg/configs.py b/slpkg/configs.py index 7acba8cc..0926cef1 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -31,6 +31,7 @@ class Configs: # pylint: disable=[R0902] deps_log_file: Path = Path(log_path, 'deps.log') slpkg_log_file: Path = Path(log_path, 'slpkg.log') upgrade_log_file: Path = Path(log_path, 'upgrade.log') + error_log_file: Path = Path(log_path, 'error.log') os_arch: str = platform.machine() file_list_suffix: str = '.pkgs' diff --git a/slpkg/main.py b/slpkg/main.py index 9986d67d..8ac3a3ba 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -3,6 +3,7 @@ import sys +import logging from pathlib import Path from signal import signal, SIGPIPE, SIG_DFL @@ -768,6 +769,13 @@ def main() -> None: Raises: SystemExit: Exit code 0. """ + # Configure logging + if Configs.error_log_file.is_file(): + Configs.error_log_file.unlink() + + logging.basicConfig(filename=Configs.error_log_file, level=logging.ERROR, + format='%(asctime)s - %(levelname)s - %(message)s') + args: list = sys.argv args.pop(0) usage = Usage() @@ -825,6 +833,7 @@ def main() -> None: try: arguments[args[0]]() except (KeyError, IndexError): + logging.error("Exception occurred", exc_info=True) usage.help_short(1) except KeyboardInterrupt as e: raise SystemExit(1) from e