mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
With this change, we provide a wrapper to `logging.getLogger` in the `aurweb.logging` module. Modules wishing to log using logging.conf should get their module-local loggers by calling `aurweb.logging.getLogger(__name__)`, similar to `logging.getLogger`, this way initialization with logging.conf is guaranteed. Signed-off-by: Kevin Morris <kevr@0cost.org>
21 lines
620 B
Python
21 lines
620 B
Python
import logging
|
|
import logging.config
|
|
import os
|
|
|
|
import aurweb.config
|
|
|
|
aurwebdir = aurweb.config.get("options", "aurwebdir")
|
|
config_path = os.path.join(aurwebdir, "logging.conf")
|
|
|
|
logging.config.fileConfig(config_path, disable_existing_loggers=False)
|
|
|
|
|
|
def get_logger(name: str) -> logging.Logger:
|
|
""" A logging.getLogger wrapper. Importing this function and
|
|
using it to get a module-local logger ensures that logging.conf
|
|
initialization is performed wherever loggers are used.
|
|
|
|
:param name: Logger name; typically `__name__`
|
|
:returns: name's logging.Logger
|
|
"""
|
|
return logging.getLogger(name)
|