Skip to content

custom log level integration #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions dj_db_conn_pool/core/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion dj_db_conn_pool/core/mixins/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

logger = logging.getLogger(__name__)


class PersistentDatabaseWrapperMixin:
def __init__(self, *args, **kwargs):
# override creation_class
Expand Down Expand Up @@ -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
Expand Down