From 69258553e03c5a4bc2eeda9247e6dec3f4309f86 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 27 Apr 2018 00:54:04 +0200 Subject: [PATCH 1/2] debian: add journald support to debian_config_common (fixes #23471) --- debian/control | 3 ++- debian/debian_config_common.py | 35 ++++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/debian/control b/debian/control index 6569d6d..0a3b5c6 100644 --- a/debian/control +++ b/debian/control @@ -19,7 +19,8 @@ Depends: ${misc:Depends}, Recommends: python-django (>= 1.8), python-gadjo, python-django-mellon (>= 1.2.22.26), - memcached + memcached, + python-systemd Description: Rapid Remote Deployment python module Package: hobo diff --git a/debian/debian_config_common.py b/debian/debian_config_common.py index a78f263..a35060e 100644 --- a/debian/debian_config_common.py +++ b/debian/debian_config_common.py @@ -9,6 +9,8 @@ # execfile('/etc/%s/settings.py' % PROJECT_NAME) import os +import warnings + from django.conf import global_settings from django.core.exceptions import ImproperlyConfigured @@ -122,22 +124,31 @@ LOGGING = { }, } -# Graylog support -if 'GRAYLOG_URL' in os.environ: +# Journald support +if os.path.exists('/run/systemd/journal/socket'): try: - from graypy import GELFHandler + from systemd import journal except ImportError: - raise ImproperlyConfigured('cannot configure graypy, import of GELFHandler failed') + warnings.warn('journald will not be used directly, please install python-systemd') else: - host = os.environ['GRAYLOG_URL'].split(':')[0] - port = int(os.environ['GRAYLOG_URL'].split(':')[1]) - LOGGING['handlers']['gelf'] = { - 'class': 'graypy.GELFHandler', - 'fqdn': True, - 'host': host, - 'port': port, + old_send = journal.send + # uppercase our own structured attributes + def send(msg, **kwargs): + for key in ['tenant', 'ip', 'path', 'application', 'request_id', + 'user_name', 'user_email', 'user_display_name', + 'user_uuid', 'user']: + if key not in kwargs: + break # fast path + value = kwargs.pop(key) + kwargs[key.upper()] = value + return old_send(msg, **kwargs) + journal.send = send + + LOGGING['handlers']['journald'] = { + 'class': 'systemd.journal.JournalHandler', } - LOGGING['loggers']['']['handlers'].append('gelf') + LOGGING['loggers']['']['handlers'].remove('syslog') + LOGGING['loggers']['']['handlers'].append('journald') # Sentry support if 'SENTRY_DSN' in os.environ: -- 2.17.0