FCM: Diagnose in eigenes Tageslog schreiben

This commit is contained in:
concierge committed 2026-11-11 08:19:58 +01:00
1 parent 94d8db2e7c
commit d2be8e0d69
7 files changed
+136

No files matched your search

+32
View File
@@ -9,6 +9,7 @@ from threading import Lock
from flask import current_app
_WS_DEBUG_LOCK = Lock()
_FCM_DEBUG_LOCK = Lock()
def write_transaction_log(tenant_id, actor_id, actor_name, action, entity_type, entity_id, details=None):
@@ -64,6 +65,37 @@ def write_ws_debug_log(tenant_id, payload):
f.write(line)
def write_fcm_debug_log(payload, tenant_id=None):
"""Schreibt FCM-Diagnosezeilen in ein separates Tageslog.
Die Flask-Logger-Ausgabe landet je nach Deployment nur in stdout,
journald oder im Gunicorn-Log. Für die Fehlersuche am Wake-Button ist
eine eigene Datei ``logs/cmbnet-fcm-YYYY-MM-DD.log`` hilfreicher. Die
Funktion ist bewusst unabhängig von der Logger-Konfiguration und kann
über ``CMBNET_FCM_DEBUG_LOG=0`` abgeschaltet werden.
"""
try:
if not current_app.config.get('FCM_DEBUG_LOG', True):
return
log_dir = Path(current_app.config['LOG_DIR'])
except Exception:
return
log_dir.mkdir(parents=True, exist_ok=True)
date_str = datetime.now().strftime('%Y-%m-%d')
log_file = log_dir / f'cmbnet-fcm-{date_str}.log'
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
tenant_part = f'[TENANT:{tenant_id}] ' if tenant_id is not None else ''
line = (
f'{timestamp} {tenant_part}FCM '
f'{json.dumps(payload, ensure_ascii=False, default=str)}\n'
)
with _FCM_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