tests: disable syslog logging handler (#51267)

This commit is contained in:
Benjamin Dauvergne 2021-02-19 08:47:45 +01:00
parent c7362f2418
commit 0f8fe28274
2 changed files with 8 additions and 4 deletions

View File

@ -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')

View File

@ -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