Skip to content

Commit 968238f

Browse files
authored
Merge pull request #227 from neutrons/logging_args
Fix string formatting issue and log return of fetchone()
2 parents 08c4a8f + ea1d151 commit 968238f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/webmon_app/reporting/report/view_util.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ def run_rate(instrument_id, n_hours=24):
271271
:param n_hours: number of hours to track
272272
"""
273273
# Try calling the stored procedure (faster)
274+
msg = "" # start with empty message to help with logging
274275
try:
275276
cursor = connection.cursor()
276277
cursor.callproc("run_rate", (instrument_id.id,))
@@ -282,6 +283,7 @@ def run_rate(instrument_id, n_hours=24):
282283
except Exception:
283284
connection.close()
284285
logging.exception("Call to stored procedure run_rate(%s) failed", str(instrument_id))
286+
logging.error("Running query from python")
285287

286288
# Do it by hand (slow)
287289
time = timezone.now()
@@ -295,6 +297,8 @@ def run_rate(instrument_id, n_hours=24):
295297
runs.append([-i, n])
296298
return runs
297299
except SystemExit:
300+
if msg: # skip empty string
301+
logging.error("message returned from fetchone: %s", str(msg))
298302
logging.exception("Call to stored procedure error_rate(%s) created system exit", str(instrument_id))
299303
raise
300304

@@ -308,6 +312,7 @@ def error_rate(instrument_id, n_hours=24):
308312
:param n_hours: number of hours to track
309313
"""
310314
# Try calling the stored procedure (faster)
315+
msg = "" # start with empty message to help with logging
311316
try:
312317
cursor = connection.cursor()
313318
cursor.callproc("error_rate", (instrument_id.id,))
@@ -316,9 +321,10 @@ def error_rate(instrument_id, n_hours=24):
316321
rows = cursor.fetchall()
317322
cursor.close()
318323
return [[int(r[0]), int(r[1])] for r in rows]
319-
except Exception as e:
324+
except Exception:
320325
connection.close()
321-
logging.exception("Call to stored procedure error_rate(%s) failed: %s", str(instrument_id), str(e))
326+
logging.exception("Call to stored procedure error_rate(%s) failed", str(instrument_id))
327+
logging.error("Running query from python")
322328

323329
# Do it by hand (slow)
324330
time = timezone.now()
@@ -335,7 +341,9 @@ def error_rate(instrument_id, n_hours=24):
335341
errors.append([-i, n])
336342
return errors
337343
except SystemExit:
338-
logging.exception("Call to stored procedure error_rate(%s) created system exit: %s", str(instrument_id))
344+
if msg: # skip empty string
345+
logging.error("message returned from fetchone: %s", str(msg))
346+
logging.exception("Call to stored procedure error_rate(%s) created system exit", str(instrument_id))
339347
raise
340348

341349

0 commit comments

Comments
 (0)