<reponame>fantes/dd_widgets
import logging

import ipywidgets


class OutputWidgetHandler(logging.Handler):
    """ Custom logging handler sending logs to an output widget """

    def __init__(self, *args, **kwargs):
        super(OutputWidgetHandler, self).__init__(*args, **kwargs)
        layout = {"width": "590px", "height": "800px", "border": "none"}
        self.out = ipywidgets.Output(layout=layout)

    def emit(self, record):
        """ Overload of logging.Handler method """
        formatted_record = self.format(record)
        new_output = {
            "name": "stdout",
            "output_type": "stream",
            "text": formatted_record + "\n",
        }
        self.out.outputs = (new_output,)  # + self.out.outputs

        # workaround for Jupyter Lab
        # https://github.com/jupyter-widgets/ipywidgets/issues/1810

        with self.out:
            print(formatted_record)

import logging

import ipywidgets


class OutputWidgetHandler(logging.Handler):
    """ Custom logging handler sending logs to an output widget """

    def __init__(self, *args, **kwargs):
        super(OutputWidgetHandler, self).__init__(*args, **kwargs)
        layout = {"width": "590px", "height": "800px", "border": "none"}
        self.out = ipywidgets.Output(layout=layout)

    def emit(self, record):
        """ Overload of logging.Handler method """
        formatted_record = self.format(record)
        new_output = {
            "name": "stdout",
            "output_type": "stream",
            "text": formatted_record + "\n",
        }
        self.out.outputs = (new_output,)  # + self.out.outputs

        # workaround for Jupyter Lab
        # https://github.com/jupyter-widgets/ipywidgets/issues/1810

        with self.out:
            print(formatted_record)
Custom logging handler sending logs to an output widget Overload of logging.Handler method # + self.out.outputs # workaround for Jupyter Lab # https://github.com/jupyter-widgets/ipywidgets/issues/1810