Skip to content

logging

OutputWidgetHandler

Bases: Handler

Custom logging handler sending logs to an output widget

Source code in src/antakia/utils/logging.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class OutputWidgetHandler(Handler):
    """Custom logging handler sending logs to an output widget"""

    def __init__(self, height: int, *args, **kwargs):
        super(OutputWidgetHandler, self).__init__(*args, **kwargs)
        layout = {"width": "100%", "height": str(height) + "px", "border": "1px solid black", "overflow_y": "auto"}
        self.out = widgets.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

    def show_logs(self):
        """Show the logs"""
        display(self.out)

    def clear_logs(self):
        """Clear the current logs"""
        self.out.clear_output()

clear_logs()

Clear the current logs

Source code in src/antakia/utils/logging.py
33
34
35
def clear_logs(self):
    """Clear the current logs"""
    self.out.clear_output()

emit(record)

Overload of logging.Handler method

Source code in src/antakia/utils/logging.py
19
20
21
22
23
24
25
26
27
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

show_logs()

Show the logs

Source code in src/antakia/utils/logging.py
29
30
31
def show_logs(self):
    """Show the logs"""
    display(self.out)