From f14f1f56fff404add34584db962636bb20217c3f Mon Sep 17 00:00:00 2001 From: Melvin PETIT Date: Fri, 22 May 2026 12:29:35 +0200 Subject: [PATCH 1/3] Refactor log display in Azure log analysis report with enhanced formatting and error highlighting --- node-client/app.js | 71 +++++++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 19 deletions(-) diff --git a/node-client/app.js b/node-client/app.js index 47cf0a2..9587c93 100644 --- a/node-client/app.js +++ b/node-client/app.js @@ -1,35 +1,68 @@ -// Client Node.js — Interroge l'API Python et affiche un rapport des logs Azure -// ----------------------------------------------------------------- - const path = require('path'); +const axios = require('axios'); +const { clear } = require('console'); -// Configuration partagée chargée depuis config.json (à la racine du projet) const config = require(path.join(__dirname, '..', 'config.json')); const API_URL = `http://${config.api.host}:${config.api.port}${config.api.route}`; -const axios = require('axios'); +/* + * This script retrieves log summaries from a Python API and prints + * a colored, human-readable Azure log analysis report to the terminal. + * It fetches counts for errors/warnings/info and lists detailed messages, + * highlighting important patterns (errors in red, warnings in yellow). + */ + +// Codes de couleur ANSI pour le terminal +const RESET = '\x1b[0m'; +const BOLD = '\x1b[1m'; +const CYAN = '\x1b[36m'; +const RED = '\x1b[31m'; +const YELLOW = '\x1b[33m'; +const GREEN = '\x1b[32m'; +const WHITE = '\x1b[37m' + +console.clear() + +const RED_WORDS = /Azure Storage|Authentication failed|Database|timeout|insufficient permissions/i; +const LOG_LIST = /Azure Storage|Authentication failed|Database|timeout|insufficient permissions|High memory|CPU usage|Disk space|SSL certificate/gi; + +function highlightLog(text) { + return text.replace(LOG_LIST, match => + RED_WORDS.test(match) ? RED + match + RESET : YELLOW + match + RESET + ); +} async function getLogs() { try { const response = await axios.get(API_URL); - const data = response.data; - console.log('\n========================================'); - console.log(' RAPPORT D\'ANALYSE DES LOGS AZURE '); - console.log('========================================'); - console.log(` Erreurs detectees : ${data.error_count}`); - console.log(` Avertissements : ${data.warning_count}`); - console.log(` Messages info : ${data.info_count}`); - console.log('\n--- Detail des erreurs ---'); - data.errors.forEach(err => console.log(` > ${err}`)); - console.log('\n--- Detail des avertissements ---'); - data.warnings.forEach(warn => console.log(` > ${warn}`)); - console.log('========================================\n'); + const now = new Date().toLocaleString('fr-FR'); + + + console.log(''); + console.log(BOLD + CYAN + '┌──────────────────────────────────────┐' + RESET); + console.log(BOLD + CYAN + '│' + WHITE + ' AZURE LOG ANALYSIS REPORT ' + CYAN + '│' + RESET); + console.log(BOLD + CYAN + '├──────────────────────────────────────┘' + RESET); + console.log(CYAN + '│ Version : ' + WHITE + `${config.version || 'N/A'}` + RESET); + console.log(CYAN + '│ Report generated at: ' + WHITE + `${now}` + RESET); + console.log(CYAN + '│' + RESET); + console.log(CYAN + '│ Errors detected : ' + WHITE + `${data.error_count}` + RESET); + console.log(CYAN + '│ Warnings : ' + WHITE + `${data.warning_count}` + RESET); + console.log(CYAN + '│ Info messages : ' + WHITE + `${data.info_count}` + RESET); + console.log(CYAN + '│' + RESET); + console.log(CYAN + '│' + RED + ' --- Error details ---' + RESET); + console.log(CYAN + '│' + RESET); + data.errors.forEach(err => console.log(CYAN + '│ ' + RED + '> ' + RESET + highlightLog(err))); + console.log(CYAN + '│' + RESET); + console.log(CYAN + '│' + YELLOW + ' --- Warning details ---' + RESET); + console.log(CYAN + '│' + RESET); + data.warnings.forEach(warn => console.log(CYAN + '│ ' + YELLOW + '> ' + RESET + highlightLog(warn))); + console.log(CYAN + '│' + RESET); } catch (error) { - console.error('Erreur de connexion a l\'API Python :', error.message); + console.error('Failed to connect to Python API:', error.message); } } -getLogs(); +getLogs(); \ No newline at end of file From 64f42a944c94e34aa7c95577dd468381fe82567f Mon Sep 17 00:00:00 2001 From: Melvin PETIT Date: Fri, 22 May 2026 13:17:15 +0200 Subject: [PATCH 2/3] Enhance log highlighting functionality with additional comments for clarity --- node-client/app.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/node-client/app.js b/node-client/app.js index 9587c93..1f8a7c5 100644 --- a/node-client/app.js +++ b/node-client/app.js @@ -23,9 +23,13 @@ const WHITE = '\x1b[37m' console.clear() +// Second list contains key word to highlight in Red const RED_WORDS = /Azure Storage|Authentication failed|Database|timeout|insufficient permissions/i; + +// First list contains key word to highlight in Yellow const LOG_LIST = /Azure Storage|Authentication failed|Database|timeout|insufficient permissions|High memory|CPU usage|Disk space|SSL certificate/gi; +// Function to highlight important log patterns in red or yellow function highlightLog(text) { return text.replace(LOG_LIST, match => RED_WORDS.test(match) ? RED + match + RESET : YELLOW + match + RESET @@ -34,9 +38,12 @@ function highlightLog(text) { async function getLogs() { try { + // Fetch log summary data from the Python API const response = await axios.get(API_URL); + // Extract data from the API response const data = response.data; + // Get current date and time in French locale format const now = new Date().toLocaleString('fr-FR'); From 8de5f8ae8e11d64e97ef3fa2725db9e21bdbece6 Mon Sep 17 00:00:00 2001 From: Melvin PETIT Date: Fri, 22 May 2026 13:22:43 +0200 Subject: [PATCH 3/3] Update project configuration to include apprenants and ensure proper formatting --- config.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config.json b/config.json index c62f739..84aaf3a 100644 --- a/config.json +++ b/config.json @@ -1,11 +1,12 @@ { "projet": "TP-Git-Collaboratif", + "version": "1.1.0", "promotion": "DevSecOps Azure — Simplon", - "apprenants": [], + "apprenants": ["..."], "api": { "port": 5000, "host": "localhost", "route": "/api/logs", "log_file": "server.log" } -} +} \ No newline at end of file