opencode ergebnis V0.1

This commit is contained in:
concierge committed 2026-10-23 00:05:06 +02:00
1 parent 61d86a3d83
commit 7e498ebc3f
71 files changed
+28982 -46

No files matched your search

View File
Whitespace-only changes.
+41
View File
@@ -0,0 +1,41 @@
"""
Transaktionslogging für CMBNet
"""
import os
from datetime import datetime
from pathlib import Path
from flask import current_app
def write_transaction_log(tenant_id, actor_id, actor_name, action, entity_type, entity_id, details=None):
"""
Schreibt einen lesbaren Eintrag ins tägliche Logfile
"""
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-{date_str}.log'
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
actor_str = f"{actor_id}({actor_name})" if actor_id and actor_name else "SYSTEM"
if isinstance(details, dict):
details_str = str(details)
elif details is None:
details_str = "{}"
else:
details_str = str(details)
log_line = f"{timestamp} [TENANT:{get_tenant_code(tenant_id)}] [ACTOR:{actor_str}] ACTION:{action} ENTITY:{entity_type}:{entity_id} DETAILS:{details_str}\n"
with open(log_file, 'a', encoding='utf-8') as f:
f.write(log_line)
def get_tenant_code(tenant_id):
"""Holt den Tenant-Code für die Logausgabe"""
from cmbnet.db import get_db
db = get_db()
tenant = db.execute('SELECT code FROM tenants WHERE id = ?', (tenant_id,)).fetchone()
return tenant['code'] if tenant else str(tenant_id)