Mejorado del log
This commit is contained in:
parent
d92eeb8c75
commit
e5346cb957
|
@ -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;
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body class="bg-gray-100">
|
||||
|
@ -477,7 +492,7 @@
|
|||
Limpiar
|
||||
</button>
|
||||
</div>
|
||||
<div id="log-area" class="bg-gray-100 p-4 rounded h-64 overflow-y-auto font-mono text-sm">
|
||||
<div id="log-area" class="bg-gray-100 p-4 rounded h-64 overflow-y-auto font-mono text-sm whitespace-pre-wrap">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue