b2in/public/_cabinet/test-logging.html
2026-01-23 17:33:10 +01:00

330 lines
12 KiB
HTML

<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cabinet Logging Test</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
max-width: 800px;
margin: 50px auto;
padding: 20px;
background-color: #f5f5f5;
}
h1 {
color: #009FE3;
border-bottom: 3px solid #009FE3;
padding-bottom: 10px;
}
.test-section {
background: white;
padding: 20px;
margin: 20px 0;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
button {
background-color: #009FE3;
color: white;
border: none;
padding: 10px 20px;
margin: 5px;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
}
button:hover {
background-color: #0082bd;
}
button.danger {
background-color: #f44336;
}
button.danger:hover {
background-color: #d32f2f;
}
button.warning {
background-color: #ff9800;
}
button.warning:hover {
background-color: #f57c00;
}
.log-output {
background-color: #1e1e1e;
color: #d4d4d4;
padding: 15px;
border-radius: 5px;
font-family: 'Courier New', monospace;
font-size: 12px;
max-height: 300px;
overflow-y: auto;
margin-top: 10px;
}
.log-entry {
margin: 5px 0;
padding: 5px;
border-left: 3px solid #009FE3;
}
.success {
color: #4caf50;
}
.error {
color: #f44336;
}
.info {
color: #009FE3;
}
code {
background-color: #f0f0f0;
padding: 2px 6px;
border-radius: 3px;
font-family: 'Courier New', monospace;
}
</style>
</head>
<body>
<h1>🧪 Cabinet Logging System - Test Interface</h1>
<p><strong>Zweck:</strong> Diese Seite testet das Logging-System, bevor es auf den Displays eingesetzt wird.</p>
<p><strong>Logs ansehen:</strong> <a href="view-logs.php" target="_blank">Log-Viewer öffnen →</a></p>
<div class="test-section">
<h2>📡 Verbindungstest</h2>
<p>Teste ob der Logger-Endpoint erreichbar ist:</p>
<button onclick="testConnection()">Verbindung testen</button>
<div id="connection-output" class="log-output" style="display:none;"></div>
</div>
<div class="test-section">
<h2>📝 Log-Level Tests</h2>
<p>Sende verschiedene Log-Levels:</p>
<button onclick="sendTestLog('INFO', 'Dies ist eine Test-Info-Nachricht')">INFO senden</button>
<button class="warning" onclick="sendTestLog('WARNING', 'Dies ist eine Test-Warnung')">WARNING senden</button>
<button class="danger" onclick="sendTestLog('ERROR', 'Dies ist ein Test-Fehler')">ERROR senden</button>
<button class="danger" onclick="sendTestLog('FATAL', 'Dies ist ein FATAL-Test-Fehler')">FATAL senden</button>
</div>
<div class="test-section">
<h2>💥 Fehler-Simulation</h2>
<p>Simuliere verschiedene Fehlertypen (erscheinen automatisch in Logs):</p>
<button class="danger" onclick="triggerRuntimeError()">Runtime Error auslösen</button>
<button class="danger" onclick="triggerPromiseRejection()">Promise Rejection auslösen</button>
<button class="warning" onclick="triggerConsoleError()">Console.error auslösen</button>
<button class="warning" onclick="triggerConsoleWarn()">Console.warn auslösen</button>
<button class="danger" onclick="triggerResourceError()">Resource Loading Error</button>
</div>
<div class="test-section">
<h2>🎯 Kontext-Test</h2>
<p>Teste Logging mit Kontext-Informationen:</p>
<button onclick="testWithContext()">Log mit Kontext senden</button>
<button onclick="testWithComplexContext()">Log mit komplexem Kontext</button>
</div>
<div class="test-section">
<h2>🔄 Performance-Test</h2>
<p>Teste mehrere Logs gleichzeitig:</p>
<button onclick="sendMultipleLogs(10)">10 Logs senden</button>
<button onclick="sendMultipleLogs(50)">50 Logs senden</button>
<button class="warning" onclick="sendMultipleLogs(100)">100 Logs senden (langsam!)</button>
</div>
<div class="test-section">
<h2>📊 Console Output</h2>
<p>Lokale Log-Ausgabe (wird auch gesendet):</p>
<div id="console-output" class="log-output"></div>
</div>
<script>
// Logger einbinden (vereinfachte Version für Tests)
const LOG_URL = 'https://cabinet.b2in.eu/logger.php';
const consoleOutput = document.getElementById('console-output');
function logToConsole(message, type = 'info') {
const entry = document.createElement('div');
entry.className = `log-entry ${type}`;
entry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
consoleOutput.appendChild(entry);
consoleOutput.scrollTop = consoleOutput.scrollHeight;
}
async function sendLog(level, message, context = {}) {
try {
const response = await fetch(LOG_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
level: level,
message: message,
timestamp: new Date().toISOString(),
context: context,
viewport: `${window.innerWidth}x${window.innerHeight}`,
connection: navigator.onLine ? 'online' : 'offline'
})
});
if (response.ok) {
logToConsole(`${level}: ${message}`, 'success');
return true;
} else {
logToConsole(`❌ Fehler beim Senden: ${response.status}`, 'error');
return false;
}
} catch (error) {
logToConsole(`❌ Network Error: ${error.message}`, 'error');
return false;
}
}
// Tests
async function testConnection() {
const output = document.getElementById('connection-output');
output.style.display = 'block';
output.innerHTML = '<div class="log-entry info">Teste Verbindung...</div>';
try {
const response = await fetch(LOG_URL, {
method: 'OPTIONS'
});
if (response.ok) {
output.innerHTML = `
<div class="log-entry success">✅ Verbindung erfolgreich!</div>
<div class="log-entry info">Status: ${response.status}</div>
<div class="log-entry info">CORS: Aktiviert</div>
`;
} else {
output.innerHTML = `
<div class="log-entry error">❌ Verbindung fehlgeschlagen</div>
<div class="log-entry error">Status: ${response.status}</div>
`;
}
} catch (error) {
output.innerHTML = `
<div class="log-entry error">❌ Netzwerkfehler: ${error.message}</div>
`;
}
}
function sendTestLog(level, message) {
sendLog(level, message, {
test: true,
source: 'test-interface'
});
}
function triggerRuntimeError() {
logToConsole('⚠️ Löse Runtime Error aus...', 'warning');
setTimeout(() => {
throw new Error('Test Runtime Error - Dies ist beabsichtigt!');
}, 100);
}
function triggerPromiseRejection() {
logToConsole('⚠️ Löse Promise Rejection aus...', 'warning');
Promise.reject('Test Promise Rejection - Dies ist beabsichtigt!');
}
function triggerConsoleError() {
console.error('Test Console Error - Dies ist beabsichtigt!', {
errorCode: 123,
test: true
});
}
function triggerConsoleWarn() {
console.warn('Test Console Warning - Dies ist beabsichtigt!', {
warningCode: 456,
test: true
});
}
function triggerResourceError() {
logToConsole('⚠️ Löse Resource Loading Error aus...', 'warning');
const img = document.createElement('img');
img.src = 'https://example.com/nonexistent-image-12345.jpg';
document.body.appendChild(img);
setTimeout(() => img.remove(), 1000);
}
function testWithContext() {
sendLog('INFO', 'Test mit Kontext-Informationen', {
testId: 'CTX-001',
user: 'Tester',
timestamp: Date.now(),
browser: navigator.userAgent
});
}
function testWithComplexContext() {
sendLog('INFO', 'Test mit komplexem Kontext', {
testId: 'CTX-002',
nested: {
level1: {
level2: {
value: 'Tief verschachtelt'
}
}
},
array: [1, 2, 3, 4, 5],
metadata: {
display: 'Test-Display',
location: 'Test-Raum',
version: '1.2'
}
});
}
async function sendMultipleLogs(count) {
logToConsole(`🚀 Sende ${count} Logs...`, 'info');
const startTime = Date.now();
for (let i = 0; i < count; i++) {
await sendLog('INFO', `Performance Test Log ${i + 1}/${count}`, {
test: 'performance',
index: i,
total: count
});
}
const duration = Date.now() - startTime;
logToConsole(`${count} Logs in ${duration}ms gesendet (${(duration/count).toFixed(2)}ms pro Log)`, 'success');
}
// Global Error Handler für Tests
window.onerror = function(msg, url, line, col, error) {
sendLog('FATAL', `JavaScript Error: ${msg}`, {
file: url,
line: line,
column: col,
stack: error?.stack
});
};
window.addEventListener('unhandledrejection', function(event) {
sendLog('ERROR', `Unhandled Promise Rejection: ${event.reason}`, {
promise: event.promise?.toString()
});
});
const originalError = console.error;
console.error = function(...args) {
sendLog('ERROR', `Console Error: ${args.join(' ')}`);
originalError.apply(console, args);
};
const originalWarn = console.warn;
console.warn = function(...args) {
sendLog('WARNING', `Console Warning: ${args.join(' ')}`);
originalWarn.apply(console, args);
};
// Initial Log
logToConsole('🚀 Test-Interface geladen', 'success');
sendLog('INFO', 'Test-Interface geöffnet', {
userAgent: navigator.userAgent,
viewport: `${window.innerWidth}x${window.innerHeight}`
});
</script>
</body>
</html>