Added logging config

This commit is contained in:
Dimitris Zlatanidis 2023-04-05 22:03:16 +03:00
parent f5e21e894c
commit 958d6b9f9b
4 changed files with 24 additions and 16 deletions

View file

@ -6,6 +6,7 @@ import tomli
import platform
from pathlib import Path
from dataclasses import dataclass
from slpkg.logging_config import LoggingConfig
class Load:
@ -46,8 +47,6 @@ class Configs:
}
prog_name: str = 'slpkg'
root_slpkg: Path = Path(Path.home(), f'.{prog_name}')
log_path: Path = Path(root_slpkg, 'logs')
os_arch: str = platform.machine()
tmp_path: str = '/tmp/'
tmp_slpkg: Path = Path(tmp_path, prog_name)
@ -115,13 +114,13 @@ class Configs:
# Creating the paths if not exists
paths = [
tmp_slpkg,
log_path,
build_path,
download_only_path,
db_path,
lib_path,
etc_path,
db_path,
build_path,
tmp_slpkg,
download_only_path,
LoggingConfig.log_path
]
for path in paths:

10
slpkg/logging_config.py Normal file
View file

@ -0,0 +1,10 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from pathlib import Path
class LoggingConfig:
root_slpkg: Path = Path(Path.home(), '.slpkg')
log_path: Path = Path(root_slpkg, 'logs')
log_file: Path = Path(log_path, 'errors_slpkg.log')

View file

@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
import logging
from pathlib import Path
from typing import Generator
from packaging.version import parse, InvalidVersion
@ -10,6 +9,7 @@ from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.sbos.queries import SBoQueries
from slpkg.binaries.queries import BinQueries
from slpkg.logging_config import LoggingConfig
class Upgrade(Configs):
@ -26,8 +26,7 @@ class Upgrade(Configs):
self.all_installed: list = self.utils.installed_package_names
log_file: Path = Path(self.log_path, 'error_upgrade.log')
logging.basicConfig(filename=log_file,
logging.basicConfig(filename=LoggingConfig.log_file,
encoding='utf-8',
level=logging.DEBUG)
@ -72,6 +71,6 @@ class Upgrade(Configs):
if parse(repo_version) == parse(inst_version) and parse(repo_build) > parse(inst_build):
return True
except InvalidVersion as err:
logging.error(err)
logging.error(f'{self.__class__.__name__}: {Upgrade.is_package_upgradeable.__name__}: {err}')
return False

View file

@ -14,6 +14,7 @@ from slpkg.blacklist import Blacklist
from slpkg.sbos.queries import SBoQueries
from slpkg.repositories import Repositories
from slpkg.binaries.queries import BinQueries
from slpkg.logging_config import LoggingConfig
class Utilities:
@ -36,8 +37,7 @@ class Utilities:
self.installed_packages: list = list(self.all_installed())
self.installed_package_names: list = list(self.all_installed_names())
log_file: Path = Path(self.configs.log_path, 'error_utilities.log')
logging.basicConfig(filename=log_file,
logging.basicConfig(filename=LoggingConfig.log_file,
encoding='utf-8',
level=logging.DEBUG)
@ -61,8 +61,8 @@ class Utilities:
if not name.startswith('.') and name not in self.black.packages():
yield file.name
except ValueError:
pass
except ValueError as err:
logging.error(f'{self.__class__.__name__}: {Utilities.all_installed.__name__}: {err}')
def all_installed_names(self) -> Generator:
""" Return all installed packages names from /val/log/packages folder. """
@ -75,7 +75,7 @@ class Utilities:
if not name.startswith('.') and name not in self.black.packages():
yield name
except ValueError as err:
logging.error(f'all_installed_names: {err}')
logging.error(f'{self.__class__.__name__}: {Utilities.all_installed_names.__name__}: {err}')
@staticmethod
def remove_file_if_exists(path: Path, file: str) -> None: