From d00b0109a611d9c73c1d6d0267c786a19d40d0a8 Mon Sep 17 00:00:00 2001 From: Markus Krogh Date: Fri, 21 Jul 2017 14:28:47 +0200 Subject: Adding sentry --- maconomy/utils.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'maconomy/utils.py') diff --git a/maconomy/utils.py b/maconomy/utils.py index de5ccdd..9092a2d 100644 --- a/maconomy/utils.py +++ b/maconomy/utils.py @@ -1,5 +1,8 @@ from collections import defaultdict import datetime +from raven import Client + +client = None def per_manager(timesheets): @@ -18,3 +21,34 @@ def employees(timesheets): def previous_monday(date=None): today = date or datetime.date.today() return today + datetime.timedelta(days=-today.weekday(), weeks=-1) + + +def is_present(what): + return what and what.strip() + + +def is_empty(what): + return not is_present(what) + + +def sentry_log(msg, extra={}): + if client: + try: + client.captureMessage(msg, extra=extra) + except: + client.captureException() + + +def sentry_exception(): + if client: + client.captureException() + + +def sentry(config): + if config.has_option('sentry', 'dsn'): + try: + dsn = config.get('sentry', 'dsn') + global client + client = Client(dsn) + except Exception as e: + print(str(e)) -- cgit v1.1