From a73e9b7408dccb7b617f64fbca6eb7232970c009 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 24 Mar 2017 11:54:50 +0100 Subject: [PATCH 2/2] add a graypy handler if GRAYLOG_URL exists (#10411) --- debian/control | 2 +- wcs/qommon/publisher.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/debian/control b/debian/control index e48bb5e..daf4490 100644 --- a/debian/control +++ b/debian/control @@ -9,7 +9,7 @@ X-Python-Version: 2.7 Package: wcs Architecture: all -Depends: ${python:Depends}, python-quixote, python-scgi, graphviz, python-feedparser, python-imaging +Depends: ${python:Depends}, python-quixote, python-scgi, graphviz, python-feedparser, python-imaging, python-graypy Recommends: python-dns, python-xlwt, python-qrcode, libjs-leaflet, python-magic Suggests: libapache2-mod-scgi | libapache-mod-scgi, python-libxml2, python-lasso, python-psycopg2 Description: web application to design and set up online forms diff --git a/wcs/qommon/publisher.py b/wcs/qommon/publisher.py index e281366..f7322cd 100644 --- a/wcs/qommon/publisher.py +++ b/wcs/qommon/publisher.py @@ -58,6 +58,11 @@ import strftime import urllib from qommon import _ +try: + import graypy +except ImportError: + graypy = None + class ImmediateRedirectException(Exception): def __init__(self, location): @@ -960,6 +965,10 @@ class QommonPublisher(Publisher, object): '%(session_id)s %(path)s %(user_id)s - %(message)s') hdlr.setFormatter(formatter) self._app_logger.addHandler(hdlr) + if os.environ.get('GRAYLOG_URL') and graypy: + host = os.environ['GRAYLOG_URL'].split(':', 1)[0] + port = int(os.environ['GRAYLOG_URL'].split(':', 1)[0]) + hdlr = graypy.GELFHandler(fqdn=True, host=host, port=port) if debug: self._app_logger.setLevel(logging.DEBUG) else: -- 2.1.4