# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import logging
+import logging.handlers
import os
import flask
_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)