import logging import structlog from django.conf import settings from rest_framework.throttling import UserRateThrottle from structlog.types import EventDict #from .models import User def structlog_add_app_info( logger: logging.Logger, method_name: str, event_dict: EventDict ) -> EventDict: event_dict["django_app"] = "vbv_lernwelt" event_dict["APP_ENVIRONMENT"] = settings.APP_ENVIRONMENT event_dict["django_app_dev_mode"] = f"vbv_lernwelt_{settings.APP_ENVIRONMENT}" return event_dict def structlog_inject_context_dict(test, level, event_dict): """ Add the structlog context dict to log events generated by the stdlib logging library. """ context_class = structlog.get_config().get("context_class") if context_class: for key, value in context_class().items(): if key not in event_dict: event_dict[key] = value return event_dict class HourUserRateThrottle(UserRateThrottle): scope = "hour-throttle" class DayUserRateThrottle(UserRateThrottle): scope = "day-throttle"