Mejorado del log
This commit is contained in:
parent
d92eeb8c75
commit
e5346cb957
|
@ -13,9 +13,7 @@
|
||||||
function initWebSocket() {
|
function initWebSocket() {
|
||||||
socket = new WebSocket(`ws://${location.host}/ws`);
|
socket = new WebSocket(`ws://${location.host}/ws`);
|
||||||
socket.onmessage = function(event) {
|
socket.onmessage = function(event) {
|
||||||
const logArea = document.getElementById('log-area');
|
addLogLine(event.data);
|
||||||
logArea.innerHTML += event.data;
|
|
||||||
logArea.scrollTop = logArea.scrollHeight;
|
|
||||||
};
|
};
|
||||||
socket.onclose = function() {
|
socket.onclose = function() {
|
||||||
console.log('WebSocket cerrado, intentando reconexión...');
|
console.log('WebSocket cerrado, intentando reconexión...');
|
||||||
|
@ -78,10 +76,7 @@
|
||||||
|
|
||||||
// Execute a script
|
// Execute a script
|
||||||
async function executeScript(scriptName) {
|
async function executeScript(scriptName) {
|
||||||
// Mostrar mensaje de inicio en los logs
|
addLogLine(`\nEjecutando script: ${scriptName}...\n`);
|
||||||
const logArea = document.getElementById('log-area');
|
|
||||||
logArea.innerHTML += `\nEjecutando script: ${scriptName}...\n`;
|
|
||||||
logArea.scrollTop = logArea.scrollHeight;
|
|
||||||
|
|
||||||
const response = await fetch('/api/execute_script', {
|
const response = await fetch('/api/execute_script', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
@ -91,9 +86,8 @@
|
||||||
|
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
logArea.innerHTML += `\nError: ${result.error}\n`;
|
addLogLine(`\nError: ${result.error}\n`);
|
||||||
}
|
}
|
||||||
logArea.scrollTop = logArea.scrollHeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Form rendering functionality
|
// Form rendering functionality
|
||||||
|
@ -382,6 +376,27 @@
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
initializeApp().catch(console.error);
|
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>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body class="bg-gray-100">
|
<body class="bg-gray-100">
|
||||||
|
@ -477,7 +492,7 @@
|
||||||
Limpiar
|
Limpiar
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue