diff --git a/slpkg/check_updates.py b/slpkg/check_updates.py index b292eb13..51738b43 100644 --- a/slpkg/check_updates.py +++ b/slpkg/check_updates.py @@ -90,7 +90,7 @@ class CheckUpdates(Configs): try: # Try to import PySocks if it's installed. from urllib3.contrib.socks import SOCKSProxyManager except (ModuleNotFoundError, ImportError): - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.compare_dates.__name__) raise SystemExit() @@ -106,7 +106,7 @@ class CheckUpdates(Configs): repo_size: int = int(repo.headers['Content-Length']) - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.info('%s: %s: %s:', self.__class__.__name__, self.__class__.compare_dates.__name__, f'{local_chg_txt=}, {local_size=}, ' diff --git a/slpkg/checksum.py b/slpkg/checksum.py index 9cb45de6..8f48ae79 100644 --- a/slpkg/checksum.py +++ b/slpkg/checksum.py @@ -52,7 +52,7 @@ class Md5sum: with open(filename, 'rb') as f: return f.read() except FileNotFoundError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.read_file.__name__) self.errors.raise_error_message(f"No such file or directory: '{filename}'", exit_status=20) diff --git a/slpkg/install_data.py b/slpkg/install_data.py index d75b1b65..e0315bd1 100644 --- a/slpkg/install_data.py +++ b/slpkg/install_data.py @@ -131,7 +131,7 @@ class InstallData(Configs): try: cache.append(checksums_dict[package_name]) except KeyError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.install_slack_data.__name__) cache.append('error checksum') @@ -222,7 +222,7 @@ class InstallData(Configs): try: cache.append(checksums_dict[package_name]) except KeyError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.install_slack_extra_data.__name__) cache.append('error checksum') @@ -313,7 +313,7 @@ class InstallData(Configs): try: cache.append(checksums_dict[package_name]) except KeyError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.install_slack_patches_data.__name__) cache.append('error checksum') @@ -405,7 +405,7 @@ class InstallData(Configs): try: cache.append(checksums_dict[package_name]) except KeyError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.install_alien_data.__name__) cache.append('error checksum') @@ -501,7 +501,7 @@ class InstallData(Configs): try: cache.append(checksums_dict[package_name]) except KeyError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.install_multilib_data.__name__) cache.append('error checksum') @@ -592,7 +592,7 @@ class InstallData(Configs): try: cache.append(checksums_dict[package_name]) except KeyError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.install_restricted_data.__name__) cache.append('error checksum') @@ -684,7 +684,7 @@ class InstallData(Configs): try: cache.append(checksums_dict[package_name]) except KeyError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.install_gnome_data.__name__) cache.append('error checksum') @@ -775,7 +775,7 @@ class InstallData(Configs): try: cache.append(checksums_dict[package_name]) except KeyError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.install_msb_data.__name__) cache.append('error checksum') @@ -866,7 +866,7 @@ class InstallData(Configs): try: cache.append(checksums_dict[package_name]) except KeyError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.install_csb_data.__name__) cache.append('error checksum') @@ -959,7 +959,7 @@ class InstallData(Configs): try: cache.append(checksums_dict[package_name]) except KeyError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.install_conraid_data.__name__) cache.append('error checksum') @@ -1051,7 +1051,7 @@ class InstallData(Configs): try: cache.append(checksums_dict[package_name]) except KeyError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.install_slackonly_data.__name__) cache.append('error checksum') @@ -1148,7 +1148,7 @@ class InstallData(Configs): try: cache.append(checksums_dict[package_name]) except KeyError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.install_salixos_data.__name__) cache.append('error checksum') @@ -1254,7 +1254,7 @@ class InstallData(Configs): try: cache.append(checksums_dict[package_name]) except KeyError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.install_salixos_extra_data.__name__) cache.append('error checksum') @@ -1360,7 +1360,7 @@ class InstallData(Configs): try: cache.append(checksums_dict[package_name]) except KeyError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.install_salixos_patches_data.__name__) cache.append('error checksum') @@ -1465,7 +1465,7 @@ class InstallData(Configs): try: cache.append(checksums_dict[package_name]) except KeyError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.install_slackel_data.__name__) cache.append('error checksum') @@ -1570,7 +1570,7 @@ class InstallData(Configs): try: cache.append(checksums_dict[package_name]) except KeyError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.install_slint_data.__name__) cache.append('error checksum') diff --git a/slpkg/logging_config.py b/slpkg/logging_config.py index b9154a63..38abf70d 100644 --- a/slpkg/logging_config.py +++ b/slpkg/logging_config.py @@ -1,13 +1,19 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- + import logging from pathlib import Path +from datetime import datetime class LoggingConfig: + dt = datetime.now() level = logging.INFO filemode: str = 'w' encoding: str = 'utf-8' log_path: Path = Path('/tmp/slpkg/logs') log_file: Path = Path(log_path, 'slpkg.log') + d: str = '%s/%s/%s' % (dt.day, dt.month, dt.year) + t: str = '%s:%s:%s' % (dt.hour, dt.minute, dt.second) + date: str = f'{d} {t}' diff --git a/slpkg/main.py b/slpkg/main.py index 48ffc9e1..19bc9dfb 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -292,8 +292,8 @@ class Argparse(Configs): encoding=LoggingConfig.encoding, level=LoggingConfig.level) - logger = logging.getLogger(__name__) - logger.info('%s: %s: %s:', self.__class__.__name__, + logger = logging.getLogger(LoggingConfig.date) + logger.info('%s: %s: %s', self.__class__.__name__, self.__class__.__init__.__name__, f'{args=}, {self.flags=}, {self.binary_repo=}') @@ -347,7 +347,7 @@ class Argparse(Configs): if opt not in options: invalid.append(opt) except (KeyError, IndexError): - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.invalid_options.__name__) self.usage.help_short(1) @@ -391,7 +391,7 @@ class Argparse(Configs): try: self.directory: str = self.args[self.args.index(arg) + 1] except IndexError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.split_options_from_args.__name__) self.directory: Path = self.tmp_slpkg @@ -406,7 +406,7 @@ class Argparse(Configs): try: self.binary_repo: str = self.args[self.args.index(arg) + 1] except IndexError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.split_options_from_args.__name__) self.binary_repo = '' @@ -771,7 +771,7 @@ class Argparse(Configs): flags = self.commands[self.args[1]] Help(self.args[1], flags).view() except KeyError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.help_for_commands.__name__) self.usage.help_minimal(f"{self.prog_name}: invalid argument '{''.join(self.args[1])}'") @@ -831,7 +831,7 @@ def main() -> None: try: arguments[args[0]]() except (KeyError, IndexError): - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s:', main.__name__) usage.help_short(1) diff --git a/slpkg/sbos/slackbuild.py b/slpkg/sbos/slackbuild.py index aad7ea89..f6245123 100644 --- a/slpkg/sbos/slackbuild.py +++ b/slpkg/sbos/slackbuild.py @@ -285,7 +285,7 @@ class Slackbuilds(Configs): try: package: str = max(packages) except ValueError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.package_for_install.__name__) self.errors.raise_error_message(f"Package '{name}' not found for install", exit_status=20) diff --git a/slpkg/upgrade.py b/slpkg/upgrade.py index 9cdacbcd..63b61d90 100644 --- a/slpkg/upgrade.py +++ b/slpkg/upgrade.py @@ -67,7 +67,7 @@ class Upgrade(Configs): repo_pkg: str = f'{name}-{repo_version}' inst_pkg: str = f'{name}-{inst_version}' - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.info('%s: %s: %s', self.__class__.__name__, self.__class__.is_package_upgradeable.__name__, f'{repo_tag=}, {repo_pkg=}, {inst_pkg=}, {parse(repo_pkg) > parse(inst_pkg)=}, ' @@ -82,6 +82,7 @@ class Upgrade(Configs): return True except InvalidVersion: + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s: %s', self.__class__.__name__, self.__class__.is_package_upgradeable.__name__, f'{repo_tag=}, {repo_pkg=}, {inst_pkg=}, {repo_pkg > inst_pkg=}, ' diff --git a/slpkg/utilities.py b/slpkg/utilities.py index e4c85e08..9de1f096 100644 --- a/slpkg/utilities.py +++ b/slpkg/utilities.py @@ -123,7 +123,7 @@ class Utilities(Configs): yield package except FileNotFoundError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.read_packages_from_file.__name__) self.errors.raise_error_message(f"No such file or directory: '{file}'", exit_status=20) @@ -134,7 +134,7 @@ class Utilities(Configs): with open(file, 'r', encoding='utf-8', errors='replace') as f: return f.readlines() except FileNotFoundError: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.read_file.__name__) self.errors.raise_error_message(f"No such file or directory: '{file}'", exit_status=20) @@ -144,7 +144,7 @@ class Utilities(Configs): try: subprocess.call(command, shell=True, stderr=stderr, stdout=stdout) except subprocess.CalledProcessError as error: - logger = logging.getLogger(__name__) + logger = logging.getLogger(LoggingConfig.date) logger.exception('%s: %s:', self.__class__.__name__, self.__class__.process.__name__) self.errors.raise_error_message(str(error), exit_status=20)