From: Benjamin Drung Date: Tue, 28 Oct 2014 10:45:21 +0000 (+0100) Subject: webhook_post2querystring.py: Log to syslog X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=f6d2c75b110d8dd6b2763d15ec9fefdee9c5fa40;p=profitbricks%2Fjenkins-build-scripts.git webhook_post2querystring.py: Log to syslog --- diff --git a/webhook_post2querystring.py b/webhook_post2querystring.py index cd2156d..49578c4 100755 --- a/webhook_post2querystring.py +++ b/webhook_post2querystring.py @@ -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)