From df82337f1f6c7eb5aaa808d555077bbf978d395b Mon Sep 17 00:00:00 2001 From: giuliof Date: Sat, 4 Sep 2021 11:13:41 +0200 Subject: [PATCH] Proper way to handle logging of exceptions --- main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 8f88bc9..4d4500e 100755 --- a/main.py +++ b/main.py @@ -122,5 +122,6 @@ try: # Wanna get a pretty JSON encoded library to do your nasty things offline at home? ;-) print(json.dumps(result, indent=4)) -except: - logging.error("Unexpected error:", sys.exc_info()[0]) +# Avoid printing on str{out,err} the unexpected exception traces. Log it instead. +except Exception as e: + logging.exception(e)