diff --git a/debian/debian_config_common.py b/debian/debian_config_common.py index 001b7df..86c7a49 100644 --- a/debian/debian_config_common.py +++ b/debian/debian_config_common.py @@ -50,6 +50,9 @@ DEBUG_LOG_FORMAT = ( '%(levelname)s \x1f%(name)s \x1f%(message)s' ) +DISABLE_GLOBAL_HANDLERS = os.environ.get('DISABLE_GLOBAL_HANDLERS') == '1' + + LOGGING = { 'version': 1, 'disable_existing_loggers': True, @@ -175,20 +178,20 @@ LOGGING = { }, # log py.warnings to syslog 'py.warnings': { - 'handlers': ['syslog_no_filter'], + 'handlers': [] if DISABLE_GLOBAL_HANDLERS else ['syslog_no_filter'], 'level': 'WARNING', 'propagate': False, }, '': { 'level': 'DEBUG', 'filters': ['request_context'], - 'handlers': ['syslog', 'mail_admins', 'debug'], + 'handlers': ([] if DISABLE_GLOBAL_HANDLERS else ['syslog']) + ['mail_admins', 'debug'], }, }, } # Journald support -if os.path.exists('/run/systemd/journal/socket'): +if os.path.exists('/run/systemd/journal/socket') and not DISABLE_GLOBAL_HANDLERS: try: from systemd import journal except ImportError: @@ -203,7 +206,7 @@ if os.path.exists('/run/systemd/journal/socket'): LOGGING['loggers']['']['handlers'].remove('syslog') LOGGING['loggers']['']['handlers'].append('journald') -elif not os.path.exists('/dev/log'): +elif not os.path.exists('/dev/log') and not DISABLE_GLOBAL_HANDLERS: # if three's no syslog (for example when building a docker image), remove # those loggers. LOGGING['loggers']['']['handlers'].remove('syslog') diff --git a/tox.ini b/tox.ini index 6518618..060f2e7 100644 --- a/tox.ini +++ b/tox.ini @@ -9,6 +9,7 @@ envlist = py3-django111-{hobo,multipublik,multitenant,schemas,authentic,passerel [testenv] usedevelop = True setenv = + DISABLE_GLOBAL_HANDLERS=1 BRANCH_NAME={env:BRANCH_NAME:} DB_ENGINE=django.db.backends.postgresql_psycopg2 SETUPTOOLS_USE_DISTUTILS=stdlib