From c1284d21c6ab557975cb6bf63bd3ae13c1dac424 Mon Sep 17 00:00:00 2001 From: Corey Hammerton Date: Mon, 16 May 2016 19:59:58 -0400 Subject: [PATCH] utils.py: Adding logging to utils.py, specifically :func:`puppetboard.utils.get_or_abort` (#235) This fixes https://github.com/voxpupuli/puppetboard/issues/230 If there are any connection issues between PuppetBoard and the PuppetDB instance there wasn't any obvious evidence in log files. This additional logging added to utils.py logs errors whenever there is an HTTPError, ConnectionError or EmptyResponseError in get_or_abort. --- puppetboard/utils.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/puppetboard/utils.py b/puppetboard/utils.py index e833b57..fe63cce 100644 --- a/puppetboard/utils.py +++ b/puppetboard/utils.py @@ -2,6 +2,7 @@ from __future__ import absolute_import from __future__ import unicode_literals import json +import logging from math import ceil from requests.exceptions import HTTPError, ConnectionError @@ -10,6 +11,8 @@ from pypuppetdb.errors import EmptyResponseError from flask import abort +log = logging.getLogger(__name__) + def jsonprint(value): return json.dumps(value, indent=2, separators=(',', ': ')) @@ -23,10 +26,13 @@ def get_or_abort(func, *args, **kwargs): try: return func(*args, **kwargs) except HTTPError as e: + log.error(str(e)) abort(e.response.status_code) except ConnectionError: + log.error(str(e)) abort(500) except EmptyResponseError: + log.error(str(e)) abort(204)