review loggers

This commit is contained in:
Evgenii Alekseev 2022-06-19 22:28:31 +03:00
parent 03c298c762
commit 18daecaac7
11 changed files with 15 additions and 91 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1 @@
../../../package/share/ahriman/settings/ahriman.ini.d/logging.ini