From 3ea1231d73f10bf905b9dc926a01311fb1b94710 Mon Sep 17 00:00:00 2001 From: Atharva Arya Date: Mon, 11 Nov 2024 14:18:37 +0530 Subject: [PATCH] Reset base.py changes and make widget in another cell --- tardis/base.py | 8 +--- tardis/io/logger/logger.py | 75 ++++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 47 deletions(-) diff --git a/tardis/base.py b/tardis/base.py index 636fac6049f..6caa3fa02f7 100644 --- a/tardis/base.py +++ b/tardis/base.py @@ -18,7 +18,6 @@ def run_tardis( log_level=None, specific_log_level=None, show_progress_bars=True, - export_logger_widget=True, **kwargs, ): """ @@ -90,7 +89,7 @@ def run_tardis( if not isinstance(show_convergence_plots, bool): raise TypeError("Expected bool in show_convergence_plots argument") - logger_widget = logging_state(log_level, tardis_config, specific_log_level) + logging_state(log_level, tardis_config, specific_log_level) if atom_data is not None: try: @@ -115,9 +114,4 @@ def run_tardis( simulation.run_convergence() simulation.run_final() - simulation.logger_widget = logger_widget - - if export_logger_widget == True: - display(logger_widget.embed()) - logger_widget.visible = False return simulation diff --git a/tardis/io/logger/logger.py b/tardis/io/logger/logger.py index 69cc6abef3c..e54ffbe0232 100644 --- a/tardis/io/logger/logger.py +++ b/tardis/io/logger/logger.py @@ -5,6 +5,36 @@ pn.extension() +def create_output_widget(height=300): + 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' + } + ) + +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"] +tabs = pn.Tabs( + *[(title, log_outputs[title]) for title in tab_order], + height=350 +) + + + @dataclass class LoggingConfig: LEVELS: dict[str, int] = field(default_factory=lambda: { @@ -34,29 +64,8 @@ class LoggingConfig: class TardisLogger: def __init__(self): self.config = LoggingConfig() - self.log_outputs = { - "WARNING/ERROR": self._create_output_widget(), - "INFO": self._create_output_widget(), - "DEBUG": self._create_output_widget(), - "ALL": self._create_output_widget(), - } self.logger = logging.getLogger("tardis") - - def _create_output_widget(self, height=300): - 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' - } - ) - + def configure_logging(self, log_level, tardis_config, specific_log_level=None): if "debug" in tardis_config: specific_log_level = tardis_config["debug"].get( @@ -106,24 +115,19 @@ def configure_logging(self, log_level, tardis_config, specific_log_level=None): for logger in tardis_loggers: logger.removeFilter(filter) + def setup_widget_logging(self): """Set up widget-based logging interface.""" - widget_handler = LoggingHandler(self.log_outputs, self.config.COLORS) + widget_handler = LoggingHandler(log_outputs, self.config.COLORS) widget_handler.setFormatter( logging.Formatter("%(name)s [%(levelname)s] %(message)s (%(filename)s:%(lineno)d)") ) self._configure_handlers(widget_handler) - tabs = self._create_and_display_tabs() - - # self.periodic_cb = pn.state.add_periodic_callback( # lambda: [output.param.trigger('object') for output in self.log_outputs.values()], # period=100 - # ) - - display(tabs) - return tabs + # ) def _configure_handlers(self, widget_handler): """Configure logging handlers.""" @@ -138,14 +142,6 @@ def _configure_handlers(self, widget_handler): self.logger.addHandler(widget_handler) logging.getLogger("py.warnings").addHandler(widget_handler) - def _create_and_display_tabs(self): - """Create and display the logging tabs.""" - tab_order = ["ALL", "WARNING/ERROR", "INFO", "DEBUG"] - tabs = pn.Tabs( - *[(title, self.log_outputs[title]) for title in tab_order], - height=350 - ) - return tabs class LoggingHandler(logging.Handler): @@ -221,5 +217,4 @@ def logging_state(log_level, tardis_config, specific_log_level=None): """Configure logging state for TARDIS.""" logger = TardisLogger() logger.configure_logging(log_level, tardis_config, specific_log_level) - widget = logger.setup_widget_logging() - return widget \ No newline at end of file + logger.setup_widget_logging()