DolostLogger

The DolostLogger module provides functionality for logging within the DOLOST framework.

class DOLOST.services.logger.DolostLogger(socketio: SocketIO, level=20)[source]

Bases: object

DolostLogger class provides a simple interface for logging messages with custom log levels and emitting those messages to a Socket.IO instance.

TRACE

Custom log level representing trace messages.

Type:

int

DEBUG

Standard logging.DEBUG level.

Type:

int

INFO

Standard logging.INFO level.

Type:

int

WARN

Custom log level representing warning messages.

Type:

int

ERROR

Standard logging.ERROR level.

Type:

int

_instance

Instance of the class.

Type:

cls

__init__(self, socketio, level=logging.INFO)[source]

Initializes a DolostLogger instance.

_get_numeric_level(self, level)[source]

Convert a log level from its string representation to the corresponding numeric value.

_register_custom_levels(self)[source]

Register custom log levels (TRACE and WARN) with the logging module.

_format_log(self, level, message)[source]

Colorize the log level and message using ANSI escape codes.

emit_socketio_message(self, message, verbose='INFO')[source]

Emits a message to a Socket.IO instance with a specified verbosity level.

log(self, message, level=logging.INFO)[source]

Logs a message with a specified log level and emits it to a Socket.IO instance.

trace(self, message, ws=True)[source]

Logs a message with the TRACE log level and emits it to a Socket.IO instance.

debug(self, message, ws=True)[source]

Logs a message with the DEBUG log level and emits it to a Socket.IO instance.

info(self, message, ws=True)[source]

Logs a message with the INFO log level and emits it to a Socket.IO instance.

warn(self, message, ws=True)[source]

Logs a message with the WARN log level and emits it to a Socket.IO instance.

error(self, message, ws=True)[source]

Logs a message with the ERROR log level and emits it to a Socket.IO instance.

debug(message, ws=True)[source]

Logs a message with the DEBUG log level and emits it to a Socket.IO instance.

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

  • ws (bool) – Emit the message over WebSockets. Defaults to True.

emit_socketio_message(message, verbose='INFO')[source]

Emits a message to a Socket.IO instance with a specified verbosity level.

Parameters:
  • message (str) – The message to emit.

  • verbose (str) – The verbosity level for the message. Defaults to ‘INFO’.

error(message, ws=True)[source]

Logs a message with the ERROR log level and emits it to a Socket.IO instance.

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

  • ws (bool) – Emit the message over WebSockets. Defaults to True.

classmethod get_instance(socketio=None, level='TRACE')[source]

Returns the instance of DolostLogger, creating it if necessary.

Parameters:
  • socketio (Socket.IO) – An instance of the Socket.IO class.

  • level (str) – The log level. Defaults to ‘TRACE’.

Returns:

An instance of DolostLogger.

Return type:

DolostLogger

info(message, ws=True)[source]

Logs a message with the INFO log level and emits it to a Socket.IO instance.

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

  • ws (bool) – Emit the message over WebSockets. Defaults to True.

log(message, ws: bool, level=20)[source]

Logs a message with a specified log level and emits it to a Socket.IO instance.

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

  • level (int) – The log level. Defaults to logging.INFO.

  • ws (bool) – Emit the message over WebSockets.

trace(message, ws=True)[source]

Logs a message with the TRACE log level and emits it to a Socket.IO instance.

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

  • ws (bool) – Emit the message over WebSockets. Defaults to True.

warn(message, ws=True)[source]

Logs a message with the WARN log level and emits it to a Socket.IO instance.

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

  • ws (bool) – Emit the message over WebSockets. Defaults to True.