Skip to content

Commit

Permalink
Add a default logging handler to avoid 'No handler found' warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebryant committed Feb 16, 2017
1 parent 725d601 commit c800a03
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions django_autoconfig/autoconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ def patterns(_, *args):
import importlib
import operator

import django_autoconfig.compat as compat

import logging
LOGGER = logging.getLogger(__name__)
# Set default logging handler to avoid "No handler found" warnings.
LOGGER.addHandler(compat.NullHandler())

MAX_ITERATIONS = 1000

Expand Down
7 changes: 7 additions & 0 deletions django_autoconfig/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import logging
try: # Python 2.7+
from logging import NullHandler # pylint: disable=unused-import
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
4 changes: 4 additions & 0 deletions django_autoconfig/environment_settings/autoconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import logging
import os

import django_autoconfig.compat

LOGGER = logging.getLogger(__name__)
# Set default logging handler to avoid "No handler found" warnings.
LOGGER.addHandler(django_autoconfig.compat.NullHandler())

def _ignore_setting(name):
return name == 'SETTINGS_MODULE'
Expand Down

0 comments on commit c800a03

Please sign in to comment.