from logging import getLogger
from pkg_resources import get_distribution

from django import apps

log = getLogger(__name__)


class AppConfig(apps.AppConfig):
    name = "axes"
    initialized = False

    @classmethod
    def initialize(cls):
        """
        Initialize Axes logging and show version information.

        This method is re-entrant and can be called multiple times.
        It displays version information exactly once at application startup.
        """

        if cls.initialized:
            return
        cls.initialized = True
        
        # Only import settings, checks, and signals one time after Django has been initialized
        from axes.conf import settings
        from axes import checks, signals  # noqa

        # Skip startup log messages if Axes is not enabled or not set to verbose
        if not settings.AXES_ENABLED:
            return

        if not settings.AXES_VERBOSE:
            return

        log.info("AXES: BEGIN LOG")
        log.info(
            "AXES: Using django-axes version %s",
            get_distribution("django-axes").version,
        )

        if settings.AXES_ONLY_USER_FAILURES:
            log.info("AXES: blocking by username only.")
        elif settings.AXES_LOCK_OUT_BY_COMBINATION_USER_AND_IP:
            log.info("AXES: blocking by combination of username and IP.")
        elif settings.AXES_LOCK_OUT_BY_USER_OR_IP:
            log.info("AXES: blocking by username or IP.")
        else:
            log.info("AXES: blocking by IP only.")

    def ready(self):
        self.initialize()

from logging import getLogger
from pkg_resources import get_distribution

from django import apps

log = getLogger(__name__)


class AppConfig(apps.AppConfig):
    name = "axes"
    initialized = False

    @classmethod
    def initialize(cls):
        """
        Initialize Axes logging and show version information.

        This method is re-entrant and can be called multiple times.
        It displays version information exactly once at application startup.
        """

        if cls.initialized:
            return
        cls.initialized = True
        
        # Only import settings, checks, and signals one time after Django has been initialized
        from axes.conf import settings
        from axes import checks, signals  # noqa

        # Skip startup log messages if Axes is not set to verbose
        if settings.AXES_VERBOSE:
            log.info("AXES: BEGIN LOG")
            log.info(
                "AXES: Using django-axes version %s",
                get_distribution("django-axes").version,
            )

            if settings.AXES_ONLY_USER_FAILURES:
                log.info("AXES: blocking by username only.")
            elif settings.AXES_LOCK_OUT_BY_COMBINATION_USER_AND_IP:
                log.info("AXES: blocking by combination of username and IP.")
            elif settings.AXES_LOCK_OUT_BY_USER_OR_IP:
                log.info("AXES: blocking by username or IP.")
            else:
                log.info("AXES: blocking by IP only.")

    def ready(self):
        self.initialize()

Adjust init verbose and enabled mode handling
Adjust init verbose and enabled mode handling

Reduce complexity and leave the enabled mode to be used
with the toggleable decorator that disables functionality
when AXES_ENABLED is set to False for testing etc.

This conforms with the previous behaviour and logic flow.
  from logging import getLogger
  from pkg_resources import get_distribution
  
  from django import apps
  
  log = getLogger(__name__)
  
  
  class AppConfig(apps.AppConfig):
      name = "axes"
      initialized = False
  
      @classmethod
      def initialize(cls):
          """
          Initialize Axes logging and show version information.
  
          This method is re-entrant and can be called multiple times.
          It displays version information exactly once at application startup.
          """
  
          if cls.initialized:
              return
          cls.initialized = True
          
          # Only import settings, checks, and signals one time after Django has been initialized
          from axes.conf import settings
          from axes import checks, signals  # noqa
  
-         # Skip startup log messages if Axes is not enabled or not set to verbose
+         # Skip startup log messages if Axes is not set to verbose
-         if not settings.AXES_ENABLED:
+         if settings.AXES_VERBOSE:
+             log.info("AXES: BEGIN LOG")
+             log.info(
+                 "AXES: Using django-axes version %s",
+                 get_distribution("django-axes").version,
-             return
+             )
  
-         if not settings.AXES_VERBOSE:
-             return
- 
-         log.info("AXES: BEGIN LOG")
-         log.info(
-             "AXES: Using django-axes version %s",
-             get_distribution("django-axes").version,
-         )
- 
-         if settings.AXES_ONLY_USER_FAILURES:
+             if settings.AXES_ONLY_USER_FAILURES:
-             log.info("AXES: blocking by username only.")
+                 log.info("AXES: blocking by username only.")
-         elif settings.AXES_LOCK_OUT_BY_COMBINATION_USER_AND_IP:
+             elif settings.AXES_LOCK_OUT_BY_COMBINATION_USER_AND_IP:
-             log.info("AXES: blocking by combination of username and IP.")
+                 log.info("AXES: blocking by combination of username and IP.")
-         elif settings.AXES_LOCK_OUT_BY_USER_OR_IP:
+             elif settings.AXES_LOCK_OUT_BY_USER_OR_IP:
-             log.info("AXES: blocking by username or IP.")
+                 log.info("AXES: blocking by username or IP.")
-         else:
+             else:
-             log.info("AXES: blocking by IP only.")
+                 log.info("AXES: blocking by IP only.")
  
      def ready(self):
          self.initialize()
  
Adjust init verbose and enabled mode handling
## Code Before:
from logging import getLogger
from pkg_resources import get_distribution

from django import apps

log = getLogger(__name__)


class AppConfig(apps.AppConfig):
    name = "axes"
    initialized = False

    @classmethod
    def initialize(cls):
        """
        Initialize Axes logging and show version information.

        This method is re-entrant and can be called multiple times.
        It displays version information exactly once at application startup.
        """

        if cls.initialized:
            return
        cls.initialized = True
        
        # Only import settings, checks, and signals one time after Django has been initialized
        from axes.conf import settings
        from axes import checks, signals  # noqa

        # Skip startup log messages if Axes is not enabled or not set to verbose
        if not settings.AXES_ENABLED:
            return

        if not settings.AXES_VERBOSE:
            return

        log.info("AXES: BEGIN LOG")
        log.info(
            "AXES: Using django-axes version %s",
            get_distribution("django-axes").version,
        )

        if settings.AXES_ONLY_USER_FAILURES:
            log.info("AXES: blocking by username only.")
        elif settings.AXES_LOCK_OUT_BY_COMBINATION_USER_AND_IP:
            log.info("AXES: blocking by combination of username and IP.")
        elif settings.AXES_LOCK_OUT_BY_USER_OR_IP:
            log.info("AXES: blocking by username or IP.")
        else:
            log.info("AXES: blocking by IP only.")

    def ready(self):
        self.initialize()

## Instruction:
Adjust init verbose and enabled mode handling
## Code After:
from logging import getLogger
from pkg_resources import get_distribution

from django import apps

log = getLogger(__name__)


class AppConfig(apps.AppConfig):
    name = "axes"
    initialized = False

    @classmethod
    def initialize(cls):
        """
        Initialize Axes logging and show version information.

        This method is re-entrant and can be called multiple times.
        It displays version information exactly once at application startup.
        """

        if cls.initialized:
            return
        cls.initialized = True
        
        # Only import settings, checks, and signals one time after Django has been initialized
        from axes.conf import settings
        from axes import checks, signals  # noqa

        # Skip startup log messages if Axes is not set to verbose
        if settings.AXES_VERBOSE:
            log.info("AXES: BEGIN LOG")
            log.info(
                "AXES: Using django-axes version %s",
                get_distribution("django-axes").version,
            )

            if settings.AXES_ONLY_USER_FAILURES:
                log.info("AXES: blocking by username only.")
            elif settings.AXES_LOCK_OUT_BY_COMBINATION_USER_AND_IP:
                log.info("AXES: blocking by combination of username and IP.")
            elif settings.AXES_LOCK_OUT_BY_USER_OR_IP:
                log.info("AXES: blocking by username or IP.")
            else:
                log.info("AXES: blocking by IP only.")

    def ready(self):
        self.initialize()
