From 3c2813c3e3d24daf4b92cd7acb088bd533d55c16 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 7 Apr 2022 08:43:43 +0200 Subject: [PATCH] logging enabled/disabled thru config --- rowers/tasks.py | 8 +++----- rowers/utils.py | 7 +++++++ rowers/views/importviews.py | 2 +- rowsandall_app/settings.py | 5 +++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/rowers/tasks.py b/rowers/tasks.py index e7c2c299..365dab3a 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -3120,9 +3120,7 @@ def df_from_summary(data): @app.task def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttimezone, debug=False, **kwargs): time.sleep(delaysec) - with open("c2_auto_import.log", "a") as errorlog: - timestr = time.strftime("%Y%m%d-%H%M%S") - errorlog.write(timestr+' '+str(c2id)+' for userid '+str(userid)+'\r\n') + dologging('c2_import.log',str(c2id)+' for userid '+str(userid)) data = alldata[c2id] splitdata = None @@ -3146,8 +3144,8 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim has_strokedata = True s = 'User {userid}, C2 ID {c2id}'.format(userid=userid, c2id=c2id) - dologging('debuglog.log', s) - dologging('debuglog.log', json.dumps(data)) + dologging('c2_import.log', s) + dologging('c2_import.log', json.dumps(data)) try: title = data['name'] diff --git a/rowers/utils.py b/rowers/utils.py index 94b87ccf..ff86496c 100644 --- a/rowers/utils.py +++ b/rowers/utils.py @@ -28,6 +28,8 @@ import iso8601 from iso8601 import ParseError import arrow +from django.conf import settings + lbstoN = 4.44822 landingpages = ( @@ -120,6 +122,11 @@ info_calls = [ def dologging(filename, s): + do_logging = settings.MYLOGGING.get(filename,True) + + if not do_logging: + return + tstamp = time.localtime() timestamp = time.strftime('%b-%d-%Y %H:%M:%S', tstamp) with open(filename, 'a') as f: diff --git a/rowers/views/importviews.py b/rowers/views/importviews.py index 541e7041..b80126d5 100644 --- a/rowers/views/importviews.py +++ b/rowers/views/importviews.py @@ -1576,7 +1576,7 @@ def workout_c2import_view(request, page=1, userid=0, message=""): rower = getrequestrower(request, userid=userid) if rower.user != request.user: messages.error( - request, 'You can only access your own workouts on the NK Logbook, not those of your athletes') + request, 'You can only access your own workouts on the Concept2 Logbook, not those of your athletes') url = reverse('workout_c2import_view', kwargs={ 'userid': request.user.id}) return HttpResponseRedirect(url) diff --git a/rowsandall_app/settings.py b/rowsandall_app/settings.py index c0165729..f95454a1 100644 --- a/rowsandall_app/settings.py +++ b/rowsandall_app/settings.py @@ -589,3 +589,8 @@ except KeyError: # pragma: no cover GEOIP_PATH = STATIC_ROOT TAGGIT_CASE_INSENSITIVE = True + +try: + MYLOGGING = CFG['logging'] +except KeyError: + MYLOGGING = {}