Broker/Protocol Analyse

This commit is contained in:
concierge committed 2026-10-31 19:14:52 +01:00
1 parent c477a05f03
commit 268e150f2b
7 files changed
+868 -2

No files matched your search

+32 -1
View File
@@ -1,11 +1,15 @@
"""
Transaktionslogging für CMBNet
"""
import os
import json
from datetime import datetime
from pathlib import Path
from threading import Lock
from flask import current_app
_WS_DEBUG_LOCK = Lock()
def write_transaction_log(tenant_id, actor_id, actor_name, action, entity_type, entity_id, details=None):
"""
@@ -33,6 +37,33 @@ def write_transaction_log(tenant_id, actor_id, actor_name, action, entity_type,
f.write(log_line)
def write_ws_debug_log(tenant_id, payload):
"""Schreibt eine Broker-Debugzeile in ein separates Tageslog.
Die Ausgabe enthält die eingehende Nachricht und den vom Broker
ermittelten Empfängerkreis. Sie ist bewusst unabhängig von der
Flask-Logger-Konfiguration, damit sie auch im Produktivbetrieb über
``CMBNET_WS_DEBUG_MESSAGES`` gezielt verfügbar ist.
"""
if not current_app.config.get('WS_DEBUG_MESSAGES', True):
return
log_dir = Path(current_app.config['LOG_DIR'])
log_dir.mkdir(parents=True, exist_ok=True)
date_str = datetime.now().strftime('%Y-%m-%d')
log_file = log_dir / f'cmbnet-ws-{date_str}.log'
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
line = (
f'{timestamp} [TENANT:{tenant_id}] WS-IN '
f'{json.dumps(payload, ensure_ascii=False, default=str)}\n'
)
with _WS_DEBUG_LOCK:
with open(log_file, 'a', encoding='utf-8') as f:
f.write(line)
def get_tenant_code(tenant_id):
"""Holt den Tenant-Code für die Logausgabe"""
from cmbnet.db import get_db