Skip to content
Snippets Groups Projects
Commit d1708a78 authored by Karim Ahmed's avatar Karim Ahmed
Browse files

fix: fix bug of missing exc_info, remove info and put back console handler for report display

parent 906c4b04
No related branches found
No related tags found
1 merge request!1059[webservice] Intoduce Global Logger for xfel-calibrate
...@@ -27,9 +27,9 @@ class CustomJsonFormatter(jsonlogger.JsonFormatter): ...@@ -27,9 +27,9 @@ class CustomJsonFormatter(jsonlogger.JsonFormatter):
log_record['lineno'] = record.lineno log_record['lineno'] = record.lineno
log_record['class'] = getattr(record, 'class', 'DefaultClass') log_record['class'] = getattr(record, 'class', 'DefaultClass')
# Get the full class hierarchy exc_info = getattr(record, 'exc_info', None)
exc_class = getattr(record, 'exc_info', (None, None, None))[0] if exc_info and exc_info[0]:
if exc_class: exc_class = exc_info[0]
class_hierarchy = [] class_hierarchy = []
current_class = exc_class current_class = exc_class
while current_class and current_class != Exception: while current_class and current_class != Exception:
...@@ -66,7 +66,11 @@ def create_job_specific_handler(log_level, file_suffix): ...@@ -66,7 +66,11 @@ def create_job_specific_handler(log_level, file_suffix):
# Create job-specific file handlers # Create job-specific file handlers
error_handler = create_job_specific_handler(logging.ERROR, 'errors') error_handler = create_job_specific_handler(logging.ERROR, 'errors')
warning_handler = create_job_specific_handler(logging.WARNING, 'warnings') 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 # Avoid errors being logged in warnings.json
warning_handler.addFilter(lambda record: record.levelno < logging.ERROR) warning_handler.addFilter(lambda record: record.levelno < logging.ERROR)
...@@ -75,12 +79,12 @@ 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() context_filter = ContextFilter()
error_handler.addFilter(context_filter) error_handler.addFilter(context_filter)
warning_handler.addFilter(context_filter) warning_handler.addFilter(context_filter)
info_handler.addFilter(context_filter) console_handler.addFilter(context_filter)
# Add handlers to logger # Add handlers to logger
logger.addHandler(error_handler) logger.addHandler(error_handler)
logger.addHandler(warning_handler) logger.addHandler(warning_handler)
logger.addHandler(info_handler) logger.addHandler(console_handler)
handling_error = False handling_error = False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment