old_contents: from .request import GLOBALS
  from django.conf import settings
  import logging
  
  
  class GrayFilter(logging.Filter):  # pragma: no cover
  
      def filter(self, record):
          if hasattr(GLOBALS, "user") and GLOBALS.user:
              record.user_id = GLOBALS.user.id
  
          record.env = settings.STATIC_LOGGING.get("env")
  
          return True
  
new_contents: import logging
  
  from django.conf import settings
  
  from .request import GLOBALS
  
  
  class GrayFilter(logging.Filter):  # pragma: no cover
      def filter(self, record):
          # check for request._cached_user before accessing the user object,
          # this means django.contrib.auth.middleware.get_user has returned.
          # This avoid hitting a recursive loop when the "django" logger level = "DEBUG".
          if hasattr(GLOBALS.request, "_cached_user") and hasattr(GLOBALS, "user") and GLOBALS.user:
              record.user_id = GLOBALS.user.id
  
          record.env = settings.STATIC_LOGGING.get("env")
  
          return True
  
subject: Fix recursive logging error wheni GrayFilter is in use and "django" logger is at DEBUG leve