Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
<!-- SPDX-License-Identifier: GPL-3.0-or-later -->
<!-- Copyright (C) 2025 Jibril Sharafi -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="/css/button.css">
<link rel="stylesheet" type="text/css" href="/css/styles.css">
<link rel="stylesheet" type="text/css" href="/css/section.css">
<link rel="stylesheet" type="text/css" href="/css/typography.css">
<link rel="stylesheet" type="text/css" href="/css/forms.css">
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
<title>Log</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" integrity="sha384-5e2ESR8Ycmos6g3gAKr1Jvwye8sW4U1u/cAKulfVJnkakCcMqhOudbtPnvJ+nbv7" crossorigin="anonymous">
<script src="/js/api-client.js"></script>
<script src="/js/issues.js"></script>
<style>
.log-table {
width: 100%;
border-collapse: collapse;
font-size: 14px;
}
.log-table th,
.log-table td {
padding: 6px;
text-align: left;
border-bottom: 1px solid #ddd;
white-space: nowrap;
}
.log-table th {
background-color: #f2f2f2;
position: sticky;
top: 0;
z-index: 10;
}
.log-table tr:hover {
background-color: #f5f5f5;
}
.search-input {
width: calc(50%);
padding: 6px;
font-size: 14px;
border: 1px solid #ddd;
border-radius: 4px;
margin-bottom: 10px;
margin-right: 30px;
cursor: text;
}
#refresh-logs {
padding: 5px 10px;
margin-bottom: 10px;
border: none;
border-radius: 3px;
font-size: 14px;
cursor: pointer;
}
.log-level {
font-weight: bold;
padding: 2px 5px;
border-radius: 3px;
}
.log-level-INFO {
background-color: #e3f2fd;
color: #0d47a1;
}
.log-level-WARNING {
background-color: #fff3e0;
color: #e65100;
}
.log-level-ERROR {
background-color: #ffebee;
color: #b71c1c;
}
.log-level-DEBUG {
background-color: #e8f5e9;
color: #1b5e20;
}
.log-level-FATAL {
background-color: #4a0e0e;
color: #ffffff;
}
.table-container {
max-height: 70vh;
overflow-y: auto;
}
.controls {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
/* Mobile responsive styles */
@media screen and (max-width: 768px) {
.search-input {
width: 100%;
margin-right: 0;
margin-bottom: 8px;
font-size: 16px; /* Prevents zoom on iOS */
padding: 10px;
}
.controls {
flex-direction: column;
align-items: stretch;
gap: 10px;
}
#refresh-logs {
margin-bottom: 0;
align-self: flex-start;
}
.table-container {
max-height: 60vh;
overflow-x: auto;
}
.log-table {
font-size: 12px;
min-width: 600px; /* Ensure table doesn't get too cramped */
}
.log-table th,
.log-table td {
padding: 4px;
white-space: nowrap;
}
.log-level {
font-size: 10px;
padding: 1px 3px;
}
/* Make certain columns more mobile-friendly */
.log-table th:first-child,
.log-table td:first-child {
min-width: 100px; /* Timestamp column */
}
.log-table th:nth-child(2),
.log-table td:nth-child(2) {
min-width: 60px; /* Level column */
}
.log-table th:last-child,
.log-table td:last-child {
min-width: 200px; /* Message column */
white-space: normal;
word-break: break-word;
}
}
@media screen and (max-width: 480px) {
.search-input {
font-size: 14px;
padding: 8px;
}
.table-container {
max-height: 50vh;
}
.log-table {
font-size: 11px;
min-width: 500px;
}
.log-table th,
.log-table td {
padding: 3px;
}
.log-level {
font-size: 9px;
padding: 1px 2px;
}
.log-table th:first-child,
.log-table td:first-child {
min-width: 80px;
}
.log-table th:nth-child(2),
.log-table td:nth-child(2) {
min-width: 50px;
}
.log-table th:last-child,
.log-table td:last-child {
min-width: 150px;
}
}
.filter-buttons {
display: flex;
gap: 10px;
}
.filter-button {
padding: 5px 10px;
border: none;
border-radius: 3px;
cursor: pointer;
font-size: 14px;
margin-bottom: 10px;
}
.filter-button.active {
font-weight: bold;
box-shadow: 0 0 0 1px #ddd;
}
#download-csv {
cursor: pointer;
}
</style>
</head>
<body>
<div class="buttonNavigation-container">
<a class="buttonNavigation" type="inner" href="/configuration">⚙️ Configuration</a>
</div>
<div class="section-box wide">
<div style="position: relative;">
<h2>Log</h2>
<button id="download-csv" class="tooltip" style="position: absolute; top: 2px; right: 2px;">
<i class="fas fa-download"></i>
</button>
<div class="controls">
<input type="text" id="search-input-text" class="search-input" placeholder="Search log..."
onkeyup="filterLogs()">
<button id="refresh-logs" type="button">
<i class="fas fa-sync-alt"></i> Refresh
</button>
<div class="filter-buttons">
<button class="filter-button active" data-level="ALL">All</button>
<button class="filter-button log-level-DEBUG" data-level="DEBUG">Debug</button>
<button class="filter-button log-level-INFO" data-level="INFO">Info</button>
<button class="filter-button log-level-WARNING" data-level="WARNING">Warning</button>
<button class="filter-button log-level-ERROR" data-level="ERROR">Error</button>
<button class="filter-button log-level-FATAL" data-level="FATAL">Fatal</button>
</div>
</div>
<div class="table-container">
<table class="log-table">
<thead>
<tr>
<th>Row</th>
<th>Timestamp</th>
<th>Elapsed</th>
<th>Level</th>
<th>Core</th>
<th>File</th>
<th>Function</th>
<th>Message</th>
</tr>
</thead>
<tbody id="log-body">
</tbody>
</table>
</div>
</div>
</div>
<script>
let isLogFetchActive = false;
let lastFetchTime = 0;
const FETCH_THROTTLE = 1000; // Minimum time between fetches in milliseconds
async function fetchLogs() {
const now = Date.now();
// If a fetch is already in progress or we haven't waited long enough, skip this fetch
if (isLogFetchActive || (now - lastFetchTime < FETCH_THROTTLE)) {
return;
}
isLogFetchActive = true;
lastFetchTime = now;
// Show loading indicator
showStatus('Loading logs...', 'info');
try {
const data = await window.energyApi.getLogs();
// If data is empty, return early
if (!data || data === '') {
return;
}
// Remove the last 4 characters if they are \r\n
let processedData = data;
if (processedData.slice(-2) === '\r\n') {
processedData = processedData.slice(0, -2);
}
const log = processedData.split('\n').map((line, index) => {
try {
// Parse new log format: [2025-08-11T19:42:51.252Z] [689 ms] [INFO ] [Core 1] [src/main.cpp:setup] Message
const parts = line.replaceAll('[', '').replaceAll('\r', '').split('] ');
if (parts.length < 6) {
// Fallback for malformed lines
return {
row: index + 1,
timestamp: '',
elapsedTime: '',
level: '',
core: '',
file: '',
functionName: '',
message: line.trim()
};
}
const timestampUtc = parts[0];
// Convert UTC timestamp to local time
let timestamp = timestampUtc;
try {
const date = new Date(timestampUtc);
if (!isNaN(date.getTime())) {
timestamp = date.toLocaleString('sv-SE', {
year: 'numeric', month: '2-digit', day: '2-digit',
hour: '2-digit', minute: '2-digit', second: '2-digit',
fractionalSecondDigits: 3
}).replace(',', '.');
}
} catch (e) { /* Keep original if conversion fails */ }
const elapsedTime = parts[1];
const level = parts[2].trim();
const core = parts[3].replace('Core ', '');
// Parse file:function from parts[4]
const moduleInfo = parts[4];
let file = '';
let functionName = '';
if (moduleInfo.includes(':')) {
const moduleParts = moduleInfo.split(':');
file = moduleParts[0];
functionName = moduleParts[1];
} else {
file = moduleInfo;
functionName = '';
}
// Rejoin remaining parts as message
const message = parts.slice(5).join('] ');
return {
row: index + 1,
timestamp,
elapsedTime,
level,
core,
file,
functionName,
message
};
} catch (error) {
return {
row: index + 1,
timestamp: '',
elapsedTime: '',
level: '',
core: '',
file: '',
functionName: '',
message: line.trim() || ''
};
}
}).reverse();
// Remove empty entries
while (log.length > 0 && log[0].message === '') log.shift();
while (log.length > 0 && log[log.length - 1].message === '') log.pop();
const logBody = document.getElementById('log-body');
logBody.innerHTML = ''; // Clear existing logs
// Use DocumentFragment for better performance
const fragment = document.createDocumentFragment();
log.forEach(logEntry => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${logEntry.row}</td>
<td>${logEntry.timestamp}</td>
<td>${logEntry.elapsedTime}</td>
<td><span class="log-level log-level-${logEntry.level}">${logEntry.level}</span></td>
<td>${logEntry.core}</td>
<td>${logEntry.file}</td>
<td>${logEntry.functionName}</td>
<td>${logEntry.message}</td>
`;
fragment.appendChild(row);
});
logBody.appendChild(fragment);
showStatus('Logs loaded successfully', 'success');
filterLogs();
} catch (error) {
console.error('Error fetching logs:', error);
} finally {
isLogFetchActive = false;
}
}
// Debounced version of filterLogs for better performance
const debouncedFilterLogs = debounce(function () {
const searchInput = document.querySelector('.search-input');
const filter = searchInput.value.toUpperCase();
const rows = document.querySelectorAll('.log-table tr');
const activeLevel = document.querySelector('.filter-button.active').dataset.level;
rows.forEach(row => {
if (row.getElementsByTagName('th').length > 0) return;
const cells = row.getElementsByTagName('td');
let found = false;
const rowLevel = cells[3].textContent.trim().toUpperCase();
if (activeLevel === 'ALL' || activeLevel === rowLevel) {
for (let i = 0; i < cells.length; i++) {
if (cells[i].textContent.toUpperCase().indexOf(filter) > -1) {
found = true;
break;
}
}
}
row.style.display = found ? '' : 'none';
});
}, 250); // 250ms debounce time
// Debounce helper function
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
// Event Listeners
document.querySelectorAll('.filter-button').forEach(button => {
button.addEventListener('click', function () {
document.querySelectorAll('.filter-button').forEach(btn =>
btn.classList.remove('active'));
this.classList.add('active');
debouncedFilterLogs();
});
});
// "Home Pro" -> "homepro", so a log export says which product it came from.
let productFileToken = 'home';
window.energyApi.getAuthStatus().then(status => {
if (status && status.productName) productFileToken = status.productName.toLowerCase().replace(/\s+/g, '');
}).catch(() => {});
document.getElementById('download-csv').addEventListener('click', function () {
const csvContent = ["data:text/csv;charset=utf-8,"];
csvContent.push("Row,Timestamp,Elapsed,Level,Core,File,Function,Message");
const rows = document.querySelectorAll('.log-table tbody tr');
rows.forEach(function (row) {
const rowData = Array.from(row.querySelectorAll('td'))
.map(cell => {
const text = cell.textContent.trim();
// Escape commas and quotes for proper CSV format
if (text.includes(',') || text.includes('"') || text.includes('\n')) {
return `"${text.replace(/"/g, '""')}"`;
}
return text;
})
.join(",");
csvContent.push(rowData);
});
const encodedUri = encodeURI(csvContent.join("\n"));
const link = document.createElement("a");
const timestamp = new Date().toISOString().replace(/[:.-]/g, "_");
link.setAttribute("href", encodedUri);
link.setAttribute("download", `energyme_${productFileToken}_log_${timestamp}.csv`);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
document.getElementById('refresh-logs').addEventListener('click', fetchLogs);
// Replace the original filterLogs function with the debounced version
const filterLogs = debouncedFilterLogs;
// Initial fetch of logs
fetchLogs();
</script>
</body>
</html>f4329a85eThis file is pinned to the selected release. Download the original to open it in your design tool.