diff --git a/tardis/base.py b/tardis/base.py index 43b2f1e3413..3563cb0ee52 100644 --- a/tardis/base.py +++ b/tardis/base.py @@ -17,7 +17,7 @@ def run_tardis( log_level=None, specific_log_level=None, show_progress_bars=True, - display_logging_widget=False, + display_logging_widget=True, **kwargs, ): """ diff --git a/tardis/io/logger/logger.py b/tardis/io/logger/logger.py index 63e4bfd9607..b62622e5591 100644 --- a/tardis/io/logger/logger.py +++ b/tardis/io/logger/logger.py @@ -4,9 +4,11 @@ from dataclasses import dataclass, field import panel as pn from IPython.display import display +from functools import lru_cache PYTHON_WARNINGS_LOGGER = logging.getLogger("py.warnings") +@lru_cache(maxsize=1) def get_environment(): """Determine the execution environment""" try: @@ -29,38 +31,38 @@ def get_environment(): return 'standard' def create_output_widget(height=300): - return pn.Feed( + return pn.pane.HTML( + "", height=height, styles={ + 'overflow-y': 'auto', + 'overflow-x': 'auto', 'border': '1px solid #ddd', 'width': '100%', 'font-family': 'monospace', 'padding': '8px', 'background-color': 'white' - }, - load_buffer=1_000_000, - view_latest=True + } ) -if get_environment() == 'vscode': - pn.extension() -else: - pn.extension(comms='ipywidgets') - -log_outputs = { +ENVIRONMENT = get_environment() +LOG_OUTPUTS = { "WARNING/ERROR": create_output_widget(), "INFO": create_output_widget(), "DEBUG": create_output_widget(), "ALL": create_output_widget(), } -tab_order = ["ALL", "WARNING/ERROR", "INFO", "DEBUG"] -logger_widget = pn.Tabs( - *[(title, log_outputs[title]) for title in tab_order], +TAB_ORDER = ["ALL", "WARNING/ERROR", "INFO", "DEBUG"] +LOGGER_WIDGET = pn.Tabs( + *[(title, LOG_OUTPUTS[title]) for title in TAB_ORDER], height=350, sizing_mode='stretch_width' ) -if get_environment() == 'vscode': - display(logger_widget) +if ENVIRONMENT == 'vscode': + pn.extension() + display(LOGGER_WIDGET) +else: + pn.extension(comms='ipywidgets') @dataclass class LoggingConfig: @@ -127,7 +129,7 @@ def _format_html_output(self, log_entry, record): return log_entry def _emit_to_widget(self, level, html_output): - """Handles the widget updates using Feed component""" + """Handles the widget updates.""" level_to_output = { logging.WARNING: "WARNING/ERROR", logging.ERROR: "WARNING/ERROR", @@ -135,17 +137,16 @@ def _emit_to_widget(self, level, html_output): logging.DEBUG: "DEBUG" } - html_wrapped = pn.pane.HTML(f"