Chunk #553
Aus: Infrastructure (Index: 2)
323
Tokens
Synced
Status
Taxonomie
| Kategorie | Infrastructure |
|---|---|
| Pfad | Infrastructure > Database Logging > Logging |
| Heading-Pfad | Infrastructure > MCP-DB Infrastructure > ProtokollLogger |
Entities
| Name | Typ |
|---|---|
| mcp_log | DATABASE |
| MySQLConnectionPool | TECHNOLOGY |
| LogEntry | CONCEPT |
| Config | CONFIG |
| ProtokollLogger | SERVICE |
Keywords
Inhalt
Logging aller Operationen nach ki_protokoll.mcp_log.
"""Logging in ki_protokoll"""
import sys
import mysql.connector.pooling as pooling
from domain.log_contract import LogEntry
from config import Config
class ProtokollLogger:
"""Schreibt in ki_protokoll.mcp_log - SRP: Nur Logging"""
def __init__(self):
self._pool = None
def _get_pool(self):
if self._pool is None:
self._pool = pooling.MySQLConnectionPool(
pool_name="log_pool",
pool_size=2,
host=Config.LOG_DB_HOST,
database=Config.LOG_DB_NAME,
user=Config.LOG_DB_USER,
password=Config.LOG_DB_PASSWORD,
charset="utf8mb4"
)
return self._pool
def log(self, entry: LogEntry) -> None:
"""Schreibt LogEntry in Datenbank."""
try:
conn = self._get_pool().get_connection()
cursor = conn.cursor()
cursor.execute(
"""INSERT INTO mcp_log
(timestamp, client_name, request, status,
duration_ms, error_message)
VALUES (%s, %s, %s, %s, %s, %s)""",
(entry.timestamp, entry.client_name, entry.request,
entry.status, entry.duration_ms, entry.error_message)
)
conn.commit()
cursor.close()
conn.close()
except Exception as e:
# Fail-Safe: Exception werfen statt silent failure
error_msg = f"CRITICAL: Failed to write to mcp_log: {str(e)}"
print(error_msg, file=sys.stderr)
raise RuntimeError(error_msg) from eClean Content
Logging aller Operationen nach ki_protokoll.mcp_log.
```
`"""Logging in ki_protokoll"""
import sys
import mysql.connector.pooling as pooling
from domain.log_contract import LogEntry
from config import Config
class ProtokollLogger:
"""Schreibt in ki_protokoll.mcp_log - SRP: Nur Logging"""
def __init__(self):
self._pool = None
def _get_pool(self):
if self._pool is None:
self._pool = pooling.MySQLConnectionPool(
pool_name="log_pool",
pool_size=2,
host=Config.LOG_DB_HOST,
database=Config.LOG_DB_NAME,
user=Config.LOG_DB_USER,
password=Config.LOG_DB_PASSWORD,
charset="utf8mb4"
)
return self._pool
def log(self, entry: LogEntry) -> None:
"""Schreibt LogEntry in Datenbank."""
try:
conn = self._get_pool().get_connection()
cursor = conn.cursor()
cursor.execute(
"""INSERT INTO mcp_log
(timestamp, client_name, request, status,
duration_ms, error_message)
VALUES (%s, %s, %s, %s, %s, %s)""",
(entry.timestamp, entry.client_name, entry.request,
entry.status, entry.duration_ms, entry.error_message)
)
conn.commit()
cursor.close()
conn.close()
except Exception as e:
# Fail-Safe: Exception werfen statt silent failure
error_msg = f"CRITICAL: Failed to write to mcp_log: {str(e)}"
print(error_msg, file=sys.stderr)
raise RuntimeError(error_msg) from e`
```
Metadaten
| Analysiert am | 20.12.2025 12:44:08 |
|---|---|
| Analyse-Modell | gemma3:4b-it-qat |
| Embedding-Modell | mxbai-embed-large |
| Qdrant-ID | cced277d-7bb9-4b42-8263-2ee865eea178 |
| Erstellt | 20.12.2025 12:34:42 |
| Aktualisiert | 20.12.2025 12:57:43 |