diff --git a/README.md b/README.md index 30035e7..8953584 100644 --- a/README.md +++ b/README.md @@ -73,15 +73,38 @@ DATABASES = { you can provide additional options to pass to SQLAlchemy's pool creation, key's name is `POOL_OPTIONS`: ```python +import logging + DATABASES = { 'default': { 'POOL_OPTIONS': { 'POOL_SIZE': 10, 'MAX_OVERFLOW': 10, - 'RECYCLE': 24 * 60 * 60 + 'RECYCLE': 24 * 60 * 60, + 'LOG_LEVEL': logging.DEBUG } } } + +# or you can define logger under 'LOGGING' for dj_db_conn_pool settings +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'handlers': { + 'console': { + 'level': 'DEBUG', + 'class': 'logging.StreamHandler', + }, + }, + 'loggers': { + 'dj_db_conn_pool': { + 'handlers': ['console'], + 'level': 'DEBUG', + 'propagate': True, + }, + }, +} + ``` `django-db-connection-pool` has more configuration options diff --git a/dj_db_conn_pool/core/__init__.py b/dj_db_conn_pool/core/__init__.py index 363378e..625e154 100644 --- a/dj_db_conn_pool/core/__init__.py +++ b/dj_db_conn_pool/core/__init__.py @@ -1,8 +1,15 @@ import threading +import logging from dj_db_conn_pool.compat import gettext_lazy as _ from dj_db_conn_pool.core.exceptions import PoolDoesNotExist +try: + from django.conf import settings + log_level = logging.DEBUG if settings.DEBUG else logging.ERROR +except ImportError: + log_level = logging.DEBUG + class PoolContainer(dict): # acquire this lock before modify pool_container @@ -16,6 +23,7 @@ class PoolContainer(dict): 'recycle': 60 * 15, 'pool_size': 10, 'max_overflow': 10, + 'LOG_LEVEL': log_level, } def has(self, pool_name): diff --git a/dj_db_conn_pool/core/mixins/core.py b/dj_db_conn_pool/core/mixins/core.py index e26b27e..f90c47f 100644 --- a/dj_db_conn_pool/core/mixins/core.py +++ b/dj_db_conn_pool/core/mixins/core.py @@ -8,7 +8,6 @@ logger = logging.getLogger(__name__) - class PersistentDatabaseWrapperMixin: def __init__(self, *args, **kwargs): # override creation_class @@ -83,6 +82,7 @@ def get_new_connection(self, conn_params): **pool_container.pool_default_params, **pool_setting } + logger.setLevel(pool_params.pop('LOG_LEVEL', logging.DEBUG)) # now we have all parameters of self.alias # create self.alias's pool