serena.gui_log_viewer#


class LogLevel(
value,
names=<not given>,
*values,
module=None,
qualname=None,
type=None,
start=1,
boundary=None,
)[source]#

Bases: Enum

class GuiLogViewer(
mode,
title='Log Viewer',
memory_log_handler=None,
width=800,
height=600,
shutdown_handler=None,
)[source]#

Bases: object

A class that creates a Tkinter GUI for displaying log messages in a separate thread. The log viewer supports coloring based on log levels (DEBUG, INFO, WARNING, ERROR). It can also highlight tool names in boldface when they appear in log messages.

Parameters:
  • mode (Literal['dashboard', 'error']) – the mode; if “dashboard”, run a dashboard with logs and some control options; if “error”, run a simple error log viewer (for fatal exceptions)

  • title – the window title

  • memory_log_handler (MemoryLogHandler | None) – an optional log handler from which to obtain log messages; If not provided, must pass the instance to a GuiLogViewerHandler to add log messages.

  • width – the initial window width

  • height – the initial window height

  • shutdown_handler (Callable[[], None] | None)

start()[source]#

Start the log viewer in a separate thread.

stop()[source]#

Stop the log viewer.

set_tool_names(tool_names)[source]#

Set or update the list of tool names to be highlighted in log messages.

Args:

tool_names (list): A list of tool name strings to highlight

add_log(message)[source]#

Add a log message to the viewer.

Args:

message (str): The log message to display

run_gui()[source]#

Run the GUI

class GuiLogViewerHandler(
log_viewer,
level=0,
format_string='%(levelname)-5s %(asctime)-15s %(name)s:%(funcName)s:%(lineno)d - %(message)s',
)[source]#

Bases: Handler

A logging handler that sends log records to a ThreadedLogViewer instance. This handler can be integrated with Python’s standard logging module to direct log entries to a GUI log viewer.

Initialize the handler with a ThreadedLogViewer instance.

Args:

log_viewer: A ThreadedLogViewer instance that will display the logs level: The logging level (default: NOTSET which captures all logs) format_string: the format string

Parameters:
emit(record)[source]#

Emit a log record to the ThreadedLogViewer.

Args:

record: The log record to emit

close()[source]#

Close the handler and optionally stop the log viewer.

stop_viewer()[source]#

Explicitly stop the associated log viewer.

show_fatal_exception(e)[source]#

Makes sure the given exception is shown in the GUI log viewer, either an existing instance or a new one.

Parameters:

e (Exception) – the exception to display