# (c) cavaliba.com - home - apps.py

from django.apps import AppConfig


class AppHomeConfig(AppConfig):
    default_auto_field = "django.db.models.BigAutoField"
    name = "app_home"

    def ready(self):
        """Reset the log2 ambient context at the start of every HTTP request; report
        CAVALIBA_LOG_* values that would be silently ignored."""

        import sys

        from django.conf import settings
        from django.core.signals import request_started

        from app_home.log import reset_on_request_started

        request_started.connect(reset_on_request_started, dispatch_uid="cavaliba_log2_reset")
        # straight to stderr: the misconfigured routing may be the one these lines need
        for warning in getattr(settings, "CAVALIBA_LOG_CONFIG_WARNINGS", []):
            sys.stderr.write(f"WARNING cavaliba logging config: {warning}\n")
