serena.util.logging#


class LogMessages(messages: list[str], max_idx: int)[source]#

Bases: object

Parameters:
  • messages (list[str])

  • max_idx (int)

messages: list[str]#

the list of log messages, ordered from oldest to newest

max_idx: int#

the 0-based index of the last message in messages (in the full log history)

class MemoryLogHandler(level=0, max_messages=2500)[source]#

Bases: Handler

Initializes the instance - basically setting the formatter to None and the filter list to empty.

Parameters:
  • level (int)

  • max_messages (int | None)

add_emit_callback(callback)[source]#

Adds a callback that will be called with each log message. The callback should accept a single string argument (the log message).

Parameters:

callback (Callable[[str], None])

Return type:

None

emit(record)[source]#

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

Parameters:

record (LogRecord)

Return type:

None

class LogBuffer(max_messages=None)[source]#

Bases: object

A thread-safe buffer for storing (an optionally limited number of) log messages.

Parameters:

max_messages (int | None)

get_log_messages(from_idx=0)[source]#
Parameters:

from_idx (int) – the 0-based index of the first log message to return. If from_idx is less than or equal to the index of the oldest message in the buffer, then all messages in the buffer will be returned.

Returns:

the list of messages

Return type:

LogMessages

class SuspendedLoggersContext[source]#

Bases: object

A context manager that provides an isolated logging environment.

Temporarily removes all root log handlers upon entry, providing a clean slate for defining new log handlers within the context. Upon exit, restores the original logging configuration. This is useful when you need to temporarily configure an isolated logging setup with well-defined log handlers.

The context manager:
  • Removes all existing (root) log handlers on entry

  • Allows defining new temporary handlers within the context

  • Restores the original configuration (handlers and root log level) on exit

Example:
>>> with SuspendedLoggersContext():
...     # No handlers are active here (configure your own and set desired log level)
...     pass
>>> # Original log handlers are restored here