Class_generator/export_logger/demo.js
StillHammer 1f8688c4aa Fix WebSocket logging system and add comprehensive network features
- Fix WebSocket server to properly broadcast logs to all connected clients
- Integrate professional logging system with real-time WebSocket interface
- Add network status indicator with DigitalOcean Spaces connectivity
- Implement AWS Signature V4 authentication for private bucket access
- Add JSON content loader with backward compatibility to JS modules
- Restore navigation breadcrumb system with comprehensive logging
- Add multiple content formats: JSON + JS with automatic discovery
- Enhance top bar with logger toggle and network status indicator
- Remove deprecated temp-games module and clean up unused files

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-15 23:05:14 +08:00

203 lines
7.3 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
// ========================================
// DÉMONSTRATION - SYSTÈME DE LOGGING
// Description: Démo complète des fonctionnalités du système de logging
// ========================================
const { logSh, setupTracer } = require('./ErrorReporting');
// Configuration du traceur pour cette démo
const tracer = setupTracer('DemoModule');
console.log(`
╔════════════════════════════════════════════════════════════╗
║ 🎬 DÉMONSTRATION LOGGING ║
║ Toutes les fonctionnalités en action ║
╚════════════════════════════════════════════════════════════╝
`);
async function demonstrationComplete() {
// 1. DÉMONSTRATION DES NIVEAUX DE LOG
console.log('\n📋 1. DÉMONSTRATION DES NIVEAUX DE LOG');
logSh('Message de trace pour débuggage détaillé', 'TRACE');
logSh('Message de debug avec informations techniques', 'DEBUG');
logSh('Message informatif standard', 'INFO');
logSh('Message d\'avertissement - situation inhabituelle', 'WARN');
logSh('Message d\'erreur - problème détecté', 'ERROR');
await sleep(1000);
// 2. DÉMONSTRATION DU TRAÇAGE HIÉRARCHIQUE
console.log('\n🌲 2. DÉMONSTRATION DU TRAÇAGE HIÉRARCHIQUE');
await tracer.run('operationPrincipale', async () => {
logSh('▶ Début opération principale', 'TRACE');
await tracer.run('preparationDonnees', async () => {
logSh('▶ Préparation des données', 'TRACE');
await sleep(500);
logSh('✔ Données préparées', 'TRACE');
}, { dataSize: '1MB', format: 'JSON' });
await tracer.run('traitementDonnees', async () => {
logSh('▶ Traitement des données', 'TRACE');
await tracer.run('validation', async () => {
logSh('▶ Validation en cours', 'TRACE');
await sleep(300);
logSh('✔ Validation réussie', 'TRACE');
}, { rules: 15, passed: 15 });
await tracer.run('transformation', async () => {
logSh('▶ Transformation des données', 'TRACE');
await sleep(400);
logSh('✔ Transformation terminée', 'TRACE');
}, { inputFormat: 'JSON', outputFormat: 'XML' });
logSh('✔ Traitement terminé', 'TRACE');
}, { records: 1500 });
logSh('✔ Opération principale terminée', 'TRACE');
}, { operationId: 'OP-2025-001', priority: 'high' });
await sleep(1000);
// 3. DÉMONSTRATION DE LA GESTION D'ERREURS
console.log('\n🚨 3. DÉMONSTRATION DE LA GESTION D\'ERREURS');
await tracer.run('operationAvecErreur', async () => {
logSh('▶ Tentative d\'opération risquée', 'TRACE');
try {
await simulerErreur();
} catch (error) {
logSh(`✖ Erreur capturée: ${error.message}`, 'ERROR');
logSh(`Stack trace: ${error.stack}`, 'DEBUG');
}
logSh('✔ Récupération d\'erreur gérée', 'TRACE');
}, { attemptNumber: 1 });
await sleep(1000);
// 4. DÉMONSTRATION DES MESSAGES CONTEXTUELS
console.log('\n🎯 4. DÉMONSTRATION DES MESSAGES CONTEXTUELS');
const userId = 'user123';
const orderId = 'ORD-456';
await tracer.run('traitementCommande', async () => {
logSh(`▶ Début traitement commande ${orderId} pour utilisateur ${userId}`, 'TRACE');
logSh(`Validation utilisateur ${userId}`, 'DEBUG');
logSh(`Utilisateur ${userId} validé avec succès`, 'INFO');
logSh(`Calcul du montant pour commande ${orderId}`, 'DEBUG');
logSh(`Montant calculé: 125.50€ pour commande ${orderId}`, 'INFO');
logSh(`Traitement paiement commande ${orderId}`, 'DEBUG');
logSh(`Paiement confirmé pour commande ${orderId}`, 'INFO');
logSh(`✔ Commande ${orderId} traitée avec succès`, 'TRACE');
}, { userId, orderId, amount: 125.50 });
await sleep(1000);
// 5. DÉMONSTRATION DES LOGS TECHNIQUES
console.log('\n⚙ 5. DÉMONSTRATION DES LOGS TECHNIQUES');
await tracer.run('operationTechnique', async () => {
logSh('▶ Connexion base de données', 'TRACE');
logSh('Paramètres connexion: host=localhost, port=5432, db=produit', 'DEBUG');
logSh('Connexion BDD établie', 'INFO');
logSh('▶ Exécution requête complexe', 'TRACE');
logSh('SQL: SELECT * FROM users WHERE active = true AND last_login > ?', 'DEBUG');
logSh('Requête exécutée en 45ms, 234 résultats', 'INFO');
logSh('▶ Mise en cache des résultats', 'TRACE');
logSh('Cache key: users_active_recent, TTL: 300s', 'DEBUG');
logSh('Données mises en cache', 'INFO');
logSh('✔ Opération technique terminée', 'TRACE');
}, { dbHost: 'localhost', cacheSize: '2.3MB' });
await sleep(1000);
// 6. DÉMONSTRATION DES LOGS PERFORMANCE
console.log('\n🏃 6. DÉMONSTRATION DES LOGS PERFORMANCE');
const startTime = Date.now();
await tracer.run('operationPerformance', async () => {
logSh('▶ Début opération critique performance', 'TRACE');
for (let i = 1; i <= 5; i++) {
await tracer.run(`etape${i}`, async () => {
logSh(`▶ Étape ${i}/5`, 'TRACE');
const stepStart = Date.now();
await sleep(100 + Math.random() * 200); // Simule du travail variable
const stepDuration = Date.now() - stepStart;
logSh(`✔ Étape ${i} terminée en ${stepDuration}ms`, 'TRACE');
}, { step: i, total: 5 });
}
const totalDuration = Date.now() - startTime;
logSh(`✔ Opération terminée en ${totalDuration}ms`, 'TRACE');
if (totalDuration > 1000) {
logSh(`Performance dégradée: ${totalDuration}ms > 1000ms`, 'WARN');
} else {
logSh('Performance satisfaisante', 'INFO');
}
}, { expectedDuration: '800ms', actualDuration: `${Date.now() - startTime}ms` });
// RÉSUMÉ FINAL
console.log(`
╔════════════════════════════════════════════════════════════╗
║ ✅ DÉMONSTRATION TERMINÉE ║
╚════════════════════════════════════════════════════════════╝
🎯 Vous avez vu en action:
• Niveaux de logs (TRACE, DEBUG, INFO, WARN, ERROR)
• Traçage hiérarchique avec contexte
• Gestion d'erreurs structurée
• Messages contextuels avec IDs
• Logs techniques détaillés
• Monitoring de performance
📊 Consulter les logs générés:
npm run logs:pretty
🌐 Interface temps réel:
npm run logs:server
# Puis ouvrir tools/logs-viewer.html
🔍 Rechercher dans les logs:
npm run logs:search
Le système de logging est maintenant configuré et opérationnel ! 🚀
`);
}
async function simulerErreur() {
await sleep(200);
throw new Error('Connexion base de données impossible - timeout après 5000ms');
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// Lancer la démonstration
if (require.main === module) {
demonstrationComplete().catch(err => {
logSh(`Erreur dans la démonstration: ${err.message}`, 'ERROR');
process.exit(1);
});
}
module.exports = { demonstrationComplete };