bug fixes

This commit is contained in:
2026-01-18 23:21:00 +03:00
parent 76baeb1038
commit ec8d67c956
7 changed files with 34 additions and 34 deletions

View File

@@ -142,9 +142,8 @@ class WebSocketLogHandler(logging.Handler):
# @POST: Instance initialized with empty deque.
# @PARAM: capacity (int) - Maximum number of logs to keep in memory.
def __init__(self, capacity: int = 1000):
with belief_scope("WebSocketLogHandler.__init__"):
super().__init__()
self.log_buffer: deque[LogEntry] = deque(maxlen=capacity)
super().__init__()
self.log_buffer: deque[LogEntry] = deque(maxlen=capacity)
# In a real implementation, you'd have a way to manage active WebSocket connections
# e.g., self.active_connections: Set[WebSocket] = set()
# [/DEF:__init__:Function]
@@ -155,26 +154,25 @@ class WebSocketLogHandler(logging.Handler):
# @POST: Log is added to the log_buffer.
# @PARAM: record (logging.LogRecord) - The log record to emit.
def emit(self, record: logging.LogRecord):
with belief_scope("WebSocketLogHandler.emit"):
try:
log_entry = LogEntry(
level=record.levelname,
message=self.format(record),
context={
"name": record.name,
"pathname": record.pathname,
"lineno": record.lineno,
"funcName": record.funcName,
"process": record.process,
"thread": record.thread,
}
)
self.log_buffer.append(log_entry)
# Here you would typically send the log_entry to all active WebSocket connections
# for real-time streaming to the frontend.
# Example: for ws in self.active_connections: await ws.send_json(log_entry.dict())
except Exception:
self.handleError(record)
try:
log_entry = LogEntry(
level=record.levelname,
message=self.format(record),
context={
"name": record.name,
"pathname": record.pathname,
"lineno": record.lineno,
"funcName": record.funcName,
"process": record.process,
"thread": record.thread,
}
)
self.log_buffer.append(log_entry)
# Here you would typically send the log_entry to all active WebSocket connections
# for real-time streaming to the frontend.
# Example: for ws in self.active_connections: await ws.send_json(log_entry.dict())
except Exception:
self.handleError(record)
# [/DEF:emit:Function]
# [DEF:get_recent_logs:Function]
@@ -183,11 +181,10 @@ class WebSocketLogHandler(logging.Handler):
# @POST: Returns list of LogEntry objects.
# @RETURN: List[LogEntry] - List of buffered log entries.
def get_recent_logs(self) -> List[LogEntry]:
with belief_scope("WebSocketLogHandler.get_recent_logs"):
"""
Returns a list of recent log entries from the buffer.
"""
return list(self.log_buffer)
"""
Returns a list of recent log entries from the buffer.
"""
return list(self.log_buffer)
# [/DEF:get_recent_logs:Function]
# [/DEF:WebSocketLogHandler:Class]