diff --git a/src/xfel_calibrate/setup_logging.py b/src/xfel_calibrate/setup_logging.py index 56309b404e3bbfa626dcfe883c7589460d752f20..ba7015e59ca29609ddbdcf06663b798d8f8d1bca 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