From 049790fcfe74e12da44ad973e3d497d41d0799dd Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 19 Feb 2021 08:47:45 +0100 Subject: [PATCH] tests: disable syslog logging handler (#51267) --- debian/debian_config_common.py | 10 ++++++---- tox.ini | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/debian/debian_config_common.py b/debian/debian_config_common.py index bcc37bc..d8173bb 100644 --- a/debian/debian_config_common.py +++ b/debian/debian_config_common.py @@ -52,6 +52,8 @@ DEBUG_LOG_FORMAT = ( '%(levelname)s \x1f%(name)s \x1f%(message)s' ) +DISABLE_GLOBAL_HANDLERS = os.environ['DISABLE_GLOBAL_HANDLERS'] == 1 + LOGGING = { 'version': 1, 'disable_existing_loggers': True, @@ -177,20 +179,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: @@ -205,7 +207,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 8c25ff8..f8ed17b 100644 --- a/tox.ini +++ b/tox.ini @@ -9,6 +9,7 @@ envlist = py2-django111-{hobo,multipublik,multitenant,multitenant-oldstylemiddle [testenv] usedevelop = True setenv = + DISABLE_GLOBAL_HANDLERS=1 BRANCH_NAME={env:BRANCH_NAME:} DB_ENGINE=django.db.backends.postgresql_psycopg2 SETUPTOOLS_USE_DISTUTILS=stdlib -- 2.30.0