feat: send logs to UI

Added SSE endpoint `/logs/stream` for the UI to listen to logs.

ref: N25B-242
This commit is contained in:
2025-11-05 13:57:51 +01:00
parent e49ccb213e
commit 220c5c7739
5 changed files with 62 additions and 18 deletions

View File

@@ -3,6 +3,9 @@ import logging.config
import os
import yaml
import zmq
from control_backend.core.config import settings
def add_logging_level(level_name: str, level_num: int, method_name: str | None = None) -> None:
@@ -38,13 +41,19 @@ def setup_logging(path: str = ".logging_config.yaml") -> None:
with open(path) as f:
try:
config = yaml.safe_load(f.read())
if "custom_levels" in config:
for level_name, level_num in config["custom_levels"].items():
add_logging_level(level_name, level_num)
logging.config.dictConfig(config)
except (AttributeError, yaml.YAMLError) as e:
logging.warning(f"Could not load logging configuration: {e}")
config = {}
if "custom_levels" in config:
for level_name, level_num in config["custom_levels"].items():
add_logging_level(level_name, level_num)
if config.get("handlers") is not None and config.get("handlers").get("ui"):
pub_socket = zmq.Context.instance().socket(zmq.PUB)
pub_socket.connect(settings.zmq_settings.internal_pub_address)
config["handlers"]["ui"]["interface_or_socket"] = pub_socket
logging.config.dictConfig(config)
else:
logging.warning("Logging config file not found. Using default logging configuration.")