added log viewer to web ui

This commit is contained in:
Chuck
2025-07-24 16:13:35 -05:00
parent 790b483298
commit 3df3b93348
2 changed files with 51 additions and 0 deletions

View File

@@ -404,6 +404,7 @@
<button class="tab-link" onclick="openTab(event, 'secrets')">API Keys</button>
<button class="tab-link" onclick="openTab(event, 'actions')">Actions</button>
<button class="tab-link" onclick="openTab(event, 'raw-json')">Raw JSON</button>
<button class="tab-link" onclick="openTab(event, 'logs')">Logs</button>
</div>
<!-- Schedule Tab -->
@@ -2300,6 +2301,15 @@
</div>
</div>
</div>
<!-- Logs Tab -->
<div id="logs" class="tab-content">
<div class="form-section">
<h2>System Logs</h2>
<p>View logs for the LED matrix service. Useful for debugging.</p>
<button id="refresh-logs-btn">Refresh Logs</button>
<pre id="log-content" style="background-color: #1e1e1e; color: #d4d4d4; padding: 15px; border-radius: 5px; max-height: 600px; overflow-y: auto; white-space: pre-wrap; word-wrap: break-word;"></pre>
</div>
</div>
</div>
<script>
@@ -2324,6 +2334,9 @@
validateJson('secrets-config-json', 'secrets-config-validation');
}, 100);
}
if (tabName === 'logs') {
fetchLogs();
}
}
function toggleJsonEditor(section) {
@@ -3503,6 +3516,26 @@
addJsonValidationListener(secretsConfigTextarea, 'secrets-config-validation');
}
});
document.getElementById('refresh-logs-btn').addEventListener('click', fetchLogs);
function fetchLogs() {
const logContent = document.getElementById('log-content');
logContent.textContent = 'Loading logs...';
fetch('/get_logs')
.then(response => response.json())
.then(data => {
if (data.status === 'success') {
logContent.textContent = data.logs;
} else {
logContent.textContent = `Error loading logs: ${data.message}`;
}
})
.catch(error => {
logContent.textContent = `Error loading logs: ${error}`;
});
}
</script>
</body>
</html>

View File

@@ -288,6 +288,24 @@ def run_action_route():
'message': f'Error running action: {e}'
}), 400
@app.route('/get_logs', methods=['GET'])
def get_logs():
try:
# Get logs from journalctl for the ledmatrix service
result = subprocess.run(
['sudo', 'journalctl', '-u', 'ledmatrix.service', '-n', '500', '--no-pager'],
capture_output=True, text=True, check=True
)
logs = result.stdout
return jsonify({'status': 'success', 'logs': logs})
except subprocess.CalledProcessError as e:
# If the command fails, return the error
error_message = f"Error fetching logs: {e.stderr}"
return jsonify({'status': 'error', 'message': error_message}), 500
except Exception as e:
# Handle other potential exceptions
return jsonify({'status': 'error', 'message': str(e)}), 500
@app.route('/save_raw_json', methods=['POST'])
def save_raw_json_route():
try: