From d1708a7895b1ddb99f564d56efa9165045f8b427 Mon Sep 17 00:00:00 2001
From: ahmedk <karim.ahmed@xfel.eu>
Date: Fri, 25 Oct 2024 10:00:31 +0200
Subject: [PATCH] fix: fix bug of missing exc_info, remove info and put back
 console handler for report display

---
 src/xfel_calibrate/setup_logging.py | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/xfel_calibrate/setup_logging.py b/src/xfel_calibrate/setup_logging.py
index 56309b404..ba7015e59 100644
--- a/src/xfel_calibrate/setup_logging.py
+++ b/src/xfel_calibrate/setup_logging.py
@@ -27,9 +27,9 @@ class CustomJsonFormatter(jsonlogger.JsonFormatter):
         log_record['lineno'] = record.lineno
         log_record['class'] = getattr(record, 'class', 'DefaultClass')
 
-        # Get the full class hierarchy
-        exc_class = getattr(record, 'exc_info', (None, None, None))[0]
-        if exc_class:
+        exc_info = getattr(record, 'exc_info', None)
+        if exc_info and exc_info[0]:
+            exc_class = exc_info[0]
             class_hierarchy = []
             current_class = exc_class
             while current_class and current_class != Exception:
@@ -66,7 +66,11 @@ def create_job_specific_handler(log_level, file_suffix):
 # Create job-specific file handlers
 error_handler = create_job_specific_handler(logging.ERROR, 'errors')
 warning_handler = create_job_specific_handler(logging.WARNING, 'warnings')
-info_handler = create_job_specific_handler(logging.INFO, 'info')
+
+# Keep console handler for notebook and slurm.out stdout
+console_handler = logging.StreamHandler()
+console_handler.setLevel(logging.INFO)
+
 
 # Avoid errors being logged in warnings.json
 warning_handler.addFilter(lambda record: record.levelno < logging.ERROR)
@@ -75,12 +79,12 @@ warning_handler.addFilter(lambda record: record.levelno < logging.ERROR)
 context_filter = ContextFilter()
 error_handler.addFilter(context_filter)
 warning_handler.addFilter(context_filter)
-info_handler.addFilter(context_filter)
+console_handler.addFilter(context_filter)
 
 # Add handlers to logger
 logger.addHandler(error_handler)
 logger.addHandler(warning_handler)
-logger.addHandler(info_handler)
+logger.addHandler(console_handler)
 
 handling_error = False
 
-- 
GitLab