From 18daecaac75b174d946986fba72609b69039b5b2 Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Sun, 19 Jun 2022 22:28:31 +0300 Subject: [PATCH] review loggers --- .../settings/ahriman.ini.d/logging.ini | 12 +--- src/ahriman/core/alpm/remote/remote.py | 2 +- src/ahriman/core/alpm/repo.py | 2 +- src/ahriman/core/build_tools/sources.py | 2 +- src/ahriman/core/build_tools/task.py | 8 +-- .../core/database/migrations/__init__.py | 2 +- .../core/database/operations/operations.py | 2 +- src/ahriman/core/sign/gpg.py | 2 +- src/ahriman/models/package.py | 2 +- tests/ahriman/core/test_configuration.py | 2 +- tests/testresources/core/logging.ini | 70 +------------------ 11 files changed, 15 insertions(+), 91 deletions(-) mode change 100644 => 120000 tests/testresources/core/logging.ini diff --git a/package/share/ahriman/settings/ahriman.ini.d/logging.ini b/package/share/ahriman/settings/ahriman.ini.d/logging.ini index 2b0c97dd..88654ec3 100644 --- a/package/share/ahriman/settings/ahriman.ini.d/logging.ini +++ b/package/share/ahriman/settings/ahriman.ini.d/logging.ini @@ -1,5 +1,5 @@ [loggers] -keys = root,build_details,database,http,stderr,boto3,botocore,nose,s3transfer +keys = root,build,http,stderr,boto3,botocore,nose,s3transfer [handlers] keys = console_handler,syslog_handler @@ -32,16 +32,10 @@ level = DEBUG handlers = syslog_handler qualname = root -[logger_build_details] +[logger_build] level = DEBUG handlers = syslog_handler -qualname = build_details -propagate = 0 - -[logger_database] -level = DEBUG -handlers = syslog_handler -qualname = database +qualname = build propagate = 0 [logger_http] diff --git a/src/ahriman/core/alpm/remote/remote.py b/src/ahriman/core/alpm/remote/remote.py index 42f09e87..45b8ad53 100644 --- a/src/ahriman/core/alpm/remote/remote.py +++ b/src/ahriman/core/alpm/remote/remote.py @@ -51,7 +51,7 @@ class Remote: """ default constructor """ - self.logger = logging.getLogger("build_details") + self.logger = logging.getLogger("build") @classmethod def info(cls: Type[Remote], package_name: str, *, pacman: Pacman) -> AURPackage: diff --git a/src/ahriman/core/alpm/repo.py b/src/ahriman/core/alpm/repo.py index 72d52fdf..0882da83 100644 --- a/src/ahriman/core/alpm/repo.py +++ b/src/ahriman/core/alpm/repo.py @@ -50,7 +50,7 @@ class Repo: paths(RepositoryPaths): repository paths instance sign_args(List[str]): additional args which have to be used to sign repository archive """ - self.logger = logging.getLogger("build_details") + self.logger = logging.getLogger("build") self.name = name self.paths = paths self.uid, _ = paths.root_owner diff --git a/src/ahriman/core/build_tools/sources.py b/src/ahriman/core/build_tools/sources.py index 19c48f18..1371bece 100644 --- a/src/ahriman/core/build_tools/sources.py +++ b/src/ahriman/core/build_tools/sources.py @@ -40,7 +40,7 @@ class Sources: """ DEFAULT_BRANCH = "master" # default fallback branch - logger = logging.getLogger("build_details") + logger = logging.getLogger("build") _check_output = check_output diff --git a/src/ahriman/core/build_tools/task.py b/src/ahriman/core/build_tools/task.py index e4aaa376..46bb20a7 100644 --- a/src/ahriman/core/build_tools/task.py +++ b/src/ahriman/core/build_tools/task.py @@ -36,7 +36,6 @@ class Task: base package build task Attributes: - build_logger(logging.Logger): logger for build process logger(logging.Logger): class logger package(Package): package definitions paths(RepositoryPaths): repository paths instance @@ -54,8 +53,7 @@ class Task: configuration(Configuration): configuration instance paths(RepositoryPaths): repository paths instance """ - self.logger = logging.getLogger("root") - self.build_logger = logging.getLogger("build_details") + self.logger = logging.getLogger("build") self.package = package self.paths = paths self.uid, _ = paths.root_owner @@ -85,14 +83,14 @@ class Task: *command, exception=BuildFailed(self.package.base), cwd=sources_dir, - logger=self.build_logger, + logger=self.logger, user=self.uid) # well it is not actually correct, but we can deal with it packages = Task._check_output("makepkg", "--packagelist", exception=BuildFailed(self.package.base), cwd=sources_dir, - logger=self.build_logger).splitlines() + logger=self.logger).splitlines() return [Path(package) for package in packages] def init(self, sources_dir: Path, database: SQLite) -> None: diff --git a/src/ahriman/core/database/migrations/__init__.py b/src/ahriman/core/database/migrations/__init__.py index f94cf1ba..de3b73cd 100644 --- a/src/ahriman/core/database/migrations/__init__.py +++ b/src/ahriman/core/database/migrations/__init__.py @@ -54,7 +54,7 @@ class Migrations: """ self.connection = connection self.configuration = configuration - self.logger = logging.getLogger("database") + self.logger = logging.getLogger("root") @classmethod def migrate(cls: Type[Migrations], connection: Connection, configuration: Configuration) -> MigrationResult: diff --git a/src/ahriman/core/database/operations/operations.py b/src/ahriman/core/database/operations/operations.py index 45a3050f..410fcaf0 100644 --- a/src/ahriman/core/database/operations/operations.py +++ b/src/ahriman/core/database/operations/operations.py @@ -45,7 +45,7 @@ class Operations: path(Path): path to the database file """ self.path = path - self.logger = logging.getLogger("database") + self.logger = logging.getLogger("root") @staticmethod def factory(cursor: Cursor, row: Tuple[Any, ...]) -> Dict[str, Any]: diff --git a/src/ahriman/core/sign/gpg.py b/src/ahriman/core/sign/gpg.py index 38e9419a..8ea99c79 100644 --- a/src/ahriman/core/sign/gpg.py +++ b/src/ahriman/core/sign/gpg.py @@ -51,7 +51,7 @@ class GPG: architecture(str): repository architecture configuration(Configuration): configuration instance """ - self.logger = logging.getLogger("build_details") + self.logger = logging.getLogger("build") self.architecture = architecture self.configuration = configuration self.targets, self.default_key = self.sign_options(configuration) diff --git a/src/ahriman/models/package.py b/src/ahriman/models/package.py index 9559bfd4..01699e10 100644 --- a/src/ahriman/models/package.py +++ b/src/ahriman/models/package.py @@ -281,7 +281,7 @@ class Package: from ahriman.core.build_tools.sources import Sources - logger = logging.getLogger("build_details") + logger = logging.getLogger("build") Sources.load(paths.cache_for(self.base), self, None, paths) try: diff --git a/tests/ahriman/core/test_configuration.py b/tests/ahriman/core/test_configuration.py index 790750eb..0dd1db50 100644 --- a/tests/ahriman/core/test_configuration.py +++ b/tests/ahriman/core/test_configuration.py @@ -267,7 +267,7 @@ def test_load_logging_fallback(configuration: Configuration, mocker: MockerFixtu """ must fallback to stderr without errors """ - mocker.patch("logging.config.fileConfig", side_effect=PermissionError()) + mocker.patch("ahriman.core.configuration.fileConfig", side_effect=PermissionError()) configuration.load_logging(quiet=False) diff --git a/tests/testresources/core/logging.ini b/tests/testresources/core/logging.ini deleted file mode 100644 index b6904b2b..00000000 --- a/tests/testresources/core/logging.ini +++ /dev/null @@ -1,69 +0,0 @@ -[loggers] -keys = root,builder,build_details,http - -[handlers] -keys = console_handler,build_file_handler,file_handler,http_handler,syslog_handler - -[formatters] -keys = generic_format,syslog_format - -[handler_console_handler] -class = StreamHandler -level = DEBUG -formatter = generic_format -args = (sys.stderr,) - -[handler_file_handler] -class = logging.handlers.RotatingFileHandler -level = DEBUG -formatter = generic_format -args = ("/var/log/ahriman/ahriman.log", "a", 20971520, 20) - -[handler_build_file_handler] -class = logging.handlers.RotatingFileHandler -level = DEBUG -formatter = generic_format -args = ("/var/log/ahriman/build.log", "a", 20971520, 20) - -[handler_http_handler] -class = logging.handlers.RotatingFileHandler -level = DEBUG -formatter = generic_format -args = ("/var/log/ahriman/http.log", "a", 20971520, 20) - -[handler_syslog_handler] -class = logging.handlers.SysLogFileHandler -level = DEBUG -formatter = syslog_format -args = ("/dev/log",) - -[formatter_generic_format] -format = [%(levelname)s %(asctime)s] [%(filename)s:%(lineno)d] [%(funcName)s]: %(message)s -datefmt = - -[formatter_syslog_format] -format = [%(levelname)s] [%(filename)s:%(lineno)d] [%(funcName)s]: %(message)s -datefmt = - -[logger_root] -level = DEBUG -handlers = syslog_handler -qualname = root - -[logger_builder] -level = DEBUG -handlers = syslog_handler -qualname = builder -propagate = 0 - -[logger_build_details] -level = DEBUG -handlers = syslog_handler -qualname = build_details -propagate = 0 - -[logger_http] -level = DEBUG -handlers = syslog_handler -qualname = http -propagate = 0 diff --git a/tests/testresources/core/logging.ini b/tests/testresources/core/logging.ini new file mode 120000 index 00000000..e5d0f33e --- /dev/null +++ b/tests/testresources/core/logging.ini @@ -0,0 +1 @@ +../../../package/share/ahriman/settings/ahriman.ini.d/logging.ini \ No newline at end of file