From 2af9b0018cf7f3152456564b6903bf89a2b8219d Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Wed, 22 Nov 2023 15:39:21 +0100
Subject: [PATCH] SQL: Minor change.

---
 src/tools.py | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/src/tools.py b/src/tools.py
index 1b778439..657752e0 100644
--- a/src/tools.py
+++ b/src/tools.py
@@ -67,6 +67,16 @@ def logger_color_reset():
         return f"{Style.RESET_ALL}"
     return ""
 
+def logger_exception(exception):
+    logger.error(
+        f"[{Fore.RED}ERROR{Style.RESET_ALL}] " +
+        f"{Fore.RED}{e}{Style.RESET_ALL}"
+    )
+    logger.debug(
+        f"{Fore.BLUE}{e}{Style.RESET_ALL}\n" +
+        f"{Fore.RED}{traceback.format_exc()}{Style.RESET_ALL}"
+    )
+
 ##########
 # TIMERS #
 ##########
@@ -135,12 +145,20 @@ def timer(func):
         try:
             value = func(*args, **kwargs)
         except Exception as e:
-            logger.debug(f"[{Fore.RED}ERROR{Style.RESET_ALL}]" +
-                         f"[{func.__module__}.{Fore.GREEN}" +
-                         f"{func.__qualname__}" +
-                         f"{Style.RESET_ALL}]: " +
-                         f"{Fore.RED}{e}{Style.RESET_ALL}")
-            traceback.print_exc()
+            logger.error(
+                f"[{Fore.RED}ERROR{Style.RESET_ALL}] " +
+                f"{Fore.RED}{e}{Style.RESET_ALL}"
+            )
+            logger.debug(
+                f"[{func.__module__}.{Fore.GREEN}" +
+                f"{func.__qualname__}" +
+                f"{Style.RESET_ALL}]: " +
+                f"{Fore.RED}{e}{Style.RESET_ALL}"
+            )
+            logger.debug(
+                f"{Fore.BLUE}{e}{Style.RESET_ALL}\n" +
+                f"{Fore.RED}{traceback.format_exc()}{Style.RESET_ALL}"
+            )
 
         end_time = time.perf_counter()
         run_time = end_time - start_time
@@ -329,11 +347,7 @@ class SQL(object):
 
             value = self._fetch(res, fetch_one)
         except Exception as e:
-            logger.error(
-                f"[{Fore.RED}ERROR{Style.RESET_ALL}] " +
-                f"{Fore.RED}{e}{Style.RESET_ALL}"
-            )
-            traceback.print_exc()
+            logger_exception(e)
         finally:
             return value
 
-- 
GitLab