Added error log file

Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
Dimitris Zlatanidis 2024-06-07 12:11:20 +03:00
parent 5c9dfe6678
commit 1ff27db619
2 changed files with 10 additions and 0 deletions

View file

@ -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'

View file

@ -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