From e5346cb9573ee734b9adf41e4ee720b4aa134711 Mon Sep 17 00:00:00 2001 From: Miguel Date: Sat, 8 Feb 2025 23:45:09 +0100 Subject: [PATCH] Mejorado del log --- templates/index.html | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/templates/index.html b/templates/index.html index 4fd9867..4e3e4b4 100644 --- a/templates/index.html +++ b/templates/index.html @@ -13,9 +13,7 @@ function initWebSocket() { socket = new WebSocket(`ws://${location.host}/ws`); socket.onmessage = function(event) { - const logArea = document.getElementById('log-area'); - logArea.innerHTML += event.data; - logArea.scrollTop = logArea.scrollHeight; + addLogLine(event.data); }; socket.onclose = function() { console.log('WebSocket cerrado, intentando reconexión...'); @@ -78,10 +76,7 @@ // Execute a script async function executeScript(scriptName) { - // Mostrar mensaje de inicio en los logs - const logArea = document.getElementById('log-area'); - logArea.innerHTML += `\nEjecutando script: ${scriptName}...\n`; - logArea.scrollTop = logArea.scrollHeight; + addLogLine(`\nEjecutando script: ${scriptName}...\n`); const response = await fetch('/api/execute_script', { method: 'POST', @@ -91,9 +86,8 @@ const result = await response.json(); if (result.error) { - logArea.innerHTML += `\nError: ${result.error}\n`; + addLogLine(`\nError: ${result.error}\n`); } - logArea.scrollTop = logArea.scrollHeight; } // Form rendering functionality @@ -382,6 +376,27 @@ document.addEventListener('DOMContentLoaded', () => { initializeApp().catch(console.error); }); + + // Función auxiliar para obtener timestamp formateado + function getTimestamp() { + const now = new Date(); + return now.toLocaleTimeString('es-ES', { + hour: '2-digit', + minute: '2-digit', + second: '2-digit' + }); + } + + // Función para agregar línea al log con timestamp + function addLogLine(message) { + const logArea = document.getElementById('log-area'); + const timestamp = getTimestamp(); + const lines = message.split('\n').map(line => + line.trim() ? `[${timestamp}] ${line}` : line + ).join('\n'); + logArea.innerHTML += lines; + logArea.scrollTop = logArea.scrollHeight; + } @@ -477,7 +492,7 @@ Limpiar -
+