Skip to content
Snippets Groups Projects
Commit 931720bc authored by Thomas Kluyver's avatar Thomas Kluyver
Browse files

Only store CalibrationWarning & subclasses in warnings file

parent 045ae80f
No related branches found
No related tags found
1 merge request!1059[webservice] Intoduce Global Logger for xfel-calibrate
......@@ -44,6 +44,7 @@ def log_error(
except Exception as e:
sys.stdout.write(f"Logging failed: {e}\n")
original_showwarning = warnings.showwarning
def handle_warning(
message: Warning, category: Type[Warning],
......@@ -52,20 +53,18 @@ def handle_warning(
file=None, line=None,
) -> None:
"""Log and display warnings."""
try:
warning_info = get_log_info(str(message), category)
if issubclass(category, CalibrationWarning):
warning_info = get_log_info(str(message), category)
with open(f"warnings_{JOB_ID}.log", "a") as log_file:
log_file.write(json.dumps(warning_info) + "\n")
with open(f"warnings_{JOB_ID}.log", "a") as log_file:
log_file.write(json.dumps(warning_info) + "\n")
except Exception as e:
sys.stdout.write(f"Warning logging failed: {e}\n")
sys.stderr.write(f"Warning logging failed: {e}\n")
finally:
# Ensure warning is displayed in notebook.
# TODO: use e.g. latex_warning from cal_tools
# to display colored warning textbox
print(f"\n{category.__name__}: {message}\n")
original_showwarning(message, category, filename, lineno, file, line)
# Get IPython shell
......
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