]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
webhook_post2querystring.py: Log to syslog
authorBenjamin Drung <benjamin.drung@profitbricks.com>
Tue, 28 Oct 2014 10:45:21 +0000 (11:45 +0100)
committerBenjamin Drung <benjamin.drung@profitbricks.com>
Tue, 28 Oct 2014 10:45:21 +0000 (11:45 +0100)
webhook_post2querystring.py

index cd2156db244691b3bcb7670982cd577a0878c651..49578c4b6ba17ffc863a8aba37e759f76ef21b81 100755 (executable)
@@ -16,6 +16,7 @@
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 import logging
+import logging.handlers
 import os
 
 import flask
@@ -27,14 +28,22 @@ JENKINS_JOB_TOKEN = "gitlab"
 _LOG_LEVEL = logging.INFO
 _LOG_FORMAT = '%(asctime)s %(name)s [%(process)d] %(levelname)s: %(message)s'
 
+
+def configure_logger():
+    logging.basicConfig(format=_LOG_FORMAT, level=_LOG_LEVEL)
+    logger = logging.getLogger(os.path.basename(__file__))
+    syslog = logging.handlers.SysLogHandler(address='/dev/log')
+    syslog.setFormatter(logging.Formatter('%(name)s: %(levelname)s %(message)s'))
+    logger.addHandler(syslog)
+    return logger
+
 app = flask.Flask(__name__)
-logging.basicConfig(format=_LOG_FORMAT, level=_LOG_LEVEL)
-logger = logging.getLogger(os.path.basename(__file__))
+logger = configure_logger()
 
 
 @app.route('/', methods=['POST'])
 def receive_gitlab_webhook():
-    logger.info("Received push event:\n{event}".format(event=flask.request.data))
+    logger.info("Received push event: {event}".format(event=flask.request.data))
     jenkins_client = jenkins.Jenkins(JENKINS_URL, None, None)
     logger.info("Sending payload to {url}job/{job} ...".format(url=JENKINS_URL, job=JENKINS_JOB))
     jenkins_client.build_job(JENKINS_JOB, {'payload': flask.request.data}, JENKINS_JOB_TOKEN)