mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix(fastapi): centralize logging initialization
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>
This commit is contained in:
parent
5ae9d09e98
commit
a06f4ec19c
10 changed files with 46 additions and 23 deletions
|
@ -8,4 +8,14 @@ aurwebdir = aurweb.config.get("options", "aurwebdir")
|
|||
config_path = os.path.join(aurwebdir, "logging.conf")
|
||||
|
||||
logging.config.fileConfig(config_path, disable_existing_loggers=False)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
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)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import logging
|
||||
|
||||
import fakeredis
|
||||
|
||||
from redis import ConnectionPool, Redis
|
||||
|
||||
import aurweb.config
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
from aurweb import logging
|
||||
|
||||
logger = logging.get_logger(__name__)
|
||||
pool = None
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import copy
|
||||
import logging
|
||||
import typing
|
||||
|
||||
from datetime import datetime
|
||||
|
@ -11,7 +10,7 @@ from sqlalchemy import and_, func, or_
|
|||
|
||||
import aurweb.config
|
||||
|
||||
from aurweb import db, l10n, models, time, util
|
||||
from aurweb import db, l10n, logging, models, time, util
|
||||
from aurweb.auth import account_type_required, auth_required
|
||||
from aurweb.captcha import get_captcha_answer, get_captcha_salts, get_captcha_token
|
||||
from aurweb.l10n import get_translator_for_request
|
||||
|
@ -21,7 +20,7 @@ from aurweb.scripts.notify import ResetKeyNotification, WelcomeNotification
|
|||
from aurweb.templates import make_context, make_variable_context, render_template
|
||||
|
||||
router = APIRouter()
|
||||
logger = logging.getLogger(__name__)
|
||||
logger = logging.get_logger(__name__)
|
||||
|
||||
|
||||
@router.get("/passreset", response_class=HTMLResponse)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import html
|
||||
import logging
|
||||
import re
|
||||
import typing
|
||||
|
||||
|
@ -10,13 +9,13 @@ from fastapi import APIRouter, Form, HTTPException, Request
|
|||
from fastapi.responses import RedirectResponse, Response
|
||||
from sqlalchemy import and_, or_
|
||||
|
||||
from aurweb import db, l10n, models
|
||||
from aurweb import db, l10n, logging, models
|
||||
from aurweb.auth import account_type_required, auth_required
|
||||
from aurweb.models.account_type import DEVELOPER, TRUSTED_USER, TRUSTED_USER_AND_DEV
|
||||
from aurweb.templates import make_context, make_variable_context, render_template
|
||||
|
||||
router = APIRouter()
|
||||
logger = logging.getLogger(__name__)
|
||||
logger = logging.get_logger(__name__)
|
||||
|
||||
# Some TU route specific constants.
|
||||
ITEMS_PER_PAGE = 10 # Paged table size.
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import logging
|
||||
import sys
|
||||
|
||||
import bleach
|
||||
|
@ -10,7 +9,9 @@ import pygit2
|
|||
import aurweb.config
|
||||
import aurweb.db
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
from aurweb import logging
|
||||
|
||||
logger = logging.get_logger(__name__)
|
||||
repo_path = aurweb.config.get('serve', 'repo-path')
|
||||
commit_uri = aurweb.config.get('options', 'commit_uri')
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import base64
|
||||
import copy
|
||||
import logging
|
||||
import math
|
||||
import random
|
||||
import re
|
||||
|
@ -20,7 +19,9 @@ from jinja2 import pass_context
|
|||
|
||||
import aurweb.config
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
from aurweb import logging
|
||||
|
||||
logger = logging.get_logger(__name__)
|
||||
|
||||
|
||||
def make_random_string(length):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue