Logger

Simple logging module for tracking and displaying messages with different statuses.

The logger is used to report messages and provide a structured way to log events and errors in the application. Logging output is shown in the standard admin page. To access the logger during algorithm execution, use the get_logger function from the algomancy_utils module.

Example

>>> from algomancy_utils import Logger
>>> logger: Logger = Logger()
...
>>> logger.log("This is a test message")
>>> logger.success("This is a test message")
>>> logger.warning("This is a test message")
class algomancy_utils.logger.MessageStatus(*values)[source]

Enum representing the status of a log message.

INFO = 'info'

Informational message

SUCCESS = 'success'

Successful operation message

WARNING = 'warning'

Warning message for potential issues

ERROR = 'error'

Error message for failed operations

class algomancy_utils.logger.Message(message, status=MessageStatus.INFO)[source]

Representation of a single log message with metadata and formatting.

Parameters:
  • message (str) – The text content of the message.

  • status (MessageStatus) – The severity or type of the message. Defaults to MessageStatus.INFO.

print()[source]

Prints the formatted message to the console with ANSI color codes based on its status.

class algomancy_utils.logger.Logger(*args, **kwargs)[source]

A logger that stores and manages a collection of log messages.

toggle_print_to_console(value=None)[source]

Toggles or sets whether log messages should be printed to the console.

Parameters:

value (bool) – Optional boolean to explicitly set the console printing state. If None, the state is toggled.

log(message, status=MessageStatus.INFO)[source]

Adds a new log message and prints it to the console if enabled.

Parameters:
  • message (str) – The message text to log.

  • status (MessageStatus) – The status/type of the message. Defaults to MessageStatus.INFO.

success(message)[source]

Logs a success message.

warning(message)[source]

Logs a warning message.

error(message)[source]

Logs an error message.

get_logs(status_filter=None)[source]

Retrieves all stored logs, optionally filtered by status.

Parameters:

status_filter (MessageStatus | None) – Optional status to filter logs by.

Returns:

A list of Message objects.

Return type:

List[Message]

clear()[source]

Removes all stored logs.

log_traceback(e)[source]

Logs the traceback of a given exception as error messages.

Parameters:

e (Exception) – The exception to log the traceback for.