Files
LogViewer/index.html

316 lines
11 KiB
HTML
Raw Normal View History

2026-04-27 18:57:25 +07:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2026-04-27 19:04:47 +07:00
<title>Log Viewer Pro</title>
2026-04-27 18:57:25 +07:00
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/dataTables.bootstrap5.min.css" rel="stylesheet">
2026-04-27 19:01:18 +07:00
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
2026-04-27 18:57:25 +07:00
<style>
body {
2026-04-27 19:04:47 +07:00
background-color: #f8f9fa;
font-size: 0.82rem;
color: #333;
}
.container-fluid {
2026-04-27 19:03:12 +07:00
padding: 20px;
2026-04-27 18:57:25 +07:00
}
2026-04-27 19:04:47 +07:00
/* Drag & Drop */
2026-04-27 18:57:25 +07:00
#drop-zone {
2026-04-27 19:04:47 +07:00
border: 2px dashed #dee2e6;
2026-04-27 19:01:18 +07:00
background: #fff;
2026-04-27 19:04:47 +07:00
padding: 25px;
2026-04-27 18:57:25 +07:00
text-align: center;
2026-04-27 19:04:47 +07:00
border-radius: 12px;
2026-04-27 18:57:25 +07:00
cursor: pointer;
2026-04-27 19:04:47 +07:00
transition: all 0.2s ease;
2026-04-27 19:03:12 +07:00
margin-bottom: 20px;
2026-04-27 18:57:25 +07:00
}
2026-04-27 19:04:47 +07:00
#drop-zone:hover,
#drop-zone.dragover {
border-color: #0d6efd;
2026-04-27 19:01:18 +07:00
background: #f0f7ff;
2026-04-27 18:57:25 +07:00
}
2026-04-27 19:04:47 +07:00
/* Table Styling */
.table-card {
2026-04-27 19:01:18 +07:00
background: #fff;
2026-04-27 19:04:47 +07:00
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
padding: 15px;
}
table.dataTable {
border-collapse: collapse !important;
border-top: 1px solid #eee;
}
.badge-lvl {
font-weight: 600;
padding: 0.4em 0.7em;
border-radius: 4px;
font-size: 0.75rem;
min-width: 45px;
display: inline-block;
text-align: center;
2026-04-27 19:01:18 +07:00
}
2026-04-27 19:04:47 +07:00
.bg-INF {
background-color: #e3f2fd;
color: #0d6efd;
2026-04-27 19:01:18 +07:00
}
2026-04-27 19:04:47 +07:00
.bg-ERR {
background-color: #ffebee;
color: #c62828;
2026-04-27 19:01:18 +07:00
}
2026-04-27 19:04:47 +07:00
.bg-DBG {
background-color: #f5f5f5;
color: #616161;
2026-04-27 18:57:25 +07:00
}
2026-04-27 19:04:47 +07:00
.bg-TRC {
background-color: #f3e5f5;
color: #7b1fa2;
2026-04-27 18:57:25 +07:00
}
2026-04-27 19:04:47 +07:00
/* Child Row / Exception */
.details-control {
2026-04-27 19:01:18 +07:00
cursor: pointer;
2026-04-27 18:57:25 +07:00
color: #0d6efd;
2026-04-27 19:04:47 +07:00
font-size: 1rem;
2026-04-27 18:57:25 +07:00
}
2026-04-27 19:04:47 +07:00
.exception-wrapper {
background: #1e1e1e;
color: #dcdcdc;
padding: 15px;
border-radius: 6px;
font-family: 'Consolas', monospace;
font-size: 0.75rem;
2026-04-27 19:01:18 +07:00
white-space: pre-wrap;
2026-04-27 19:04:47 +07:00
margin: 10px 0;
border-left: 4px solid #c62828;
}
/* Utils */
.text-truncate-custom {
max-width: 500px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: inline-block;
vertical-align: bottom;
2026-04-27 18:57:25 +07:00
}
2026-04-27 19:04:47 +07:00
.btn-more {
2026-04-27 19:01:18 +07:00
color: #0d6efd;
text-decoration: underline;
2026-04-27 19:04:47 +07:00
cursor: pointer;
2026-04-27 19:03:12 +07:00
font-weight: 500;
2026-04-27 19:04:47 +07:00
margin-left: 5px;
2026-04-27 19:03:12 +07:00
}
2026-04-27 19:04:47 +07:00
.props-text {
color: #666;
font-style: italic;
font-size: 0.75rem;
2026-04-27 18:57:25 +07:00
}
</style>
</head>
<body>
2026-04-27 19:03:12 +07:00
<div class="container-fluid">
2026-04-27 19:01:18 +07:00
<div id="drop-zone" onclick="document.getElementById('file-input').click()">
2026-04-27 19:04:47 +07:00
<h5 class="mb-1"><i class="bi bi-file-earmark-arrow-up text-primary"></i> Drop your .log file here</h5>
<p class="text-muted small mb-0">The parser handles timestamped headers and multi-line exceptions
automatically.</p>
2026-04-27 19:01:18 +07:00
<input type="file" id="file-input" hidden accept=".log,.txt">
2026-04-27 18:57:25 +07:00
</div>
2026-04-27 19:04:47 +07:00
<div class="table-card">
<div class="d-flex justify-content-between align-items-center mb-3">
<div class="d-flex gap-2">
<select id="level-filter" class="form-select form-select-sm" style="width: 140px;">
<option value="">All Levels</option>
<option value="INF">INF</option>
<option value="ERR">ERR</option>
<option value="DBG">DBG</option>
<option value="TRC">TRC</option>
2026-04-27 18:57:25 +07:00
</select>
</div>
2026-04-27 19:04:47 +07:00
<div id="search-container"></div>
2026-04-27 18:57:25 +07:00
</div>
2026-04-27 19:04:47 +07:00
<table id="log-table" class="table table-hover table-sm w-100">
2026-04-27 19:01:18 +07:00
<thead>
2026-04-27 18:57:25 +07:00
<tr>
2026-04-27 19:01:18 +07:00
<th width="30"></th>
2026-04-27 19:04:47 +07:00
<th width="100">Timestamp</th>
<th width="60">Lvl</th>
2026-04-27 18:57:25 +07:00
<th>Message</th>
2026-04-27 19:04:47 +07:00
<th width="250">Properties</th>
2026-04-27 18:57:25 +07:00
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
2026-04-27 19:01:18 +07:00
<div class="modal fade" id="logModal" tabindex="-1">
2026-04-27 19:04:47 +07:00
<div class="modal-dialog modal-lg">
2026-04-27 19:01:18 +07:00
<div class="modal-content">
2026-04-27 19:04:47 +07:00
<div class="modal-header py-2 px-3">
<h6 class="modal-title">Full Message Log</h6>
2026-04-27 19:01:18 +07:00
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
2026-04-27 19:04:47 +07:00
<div class="modal-body bg-light">
<div id="modal-body-content"
style="white-space: pre-wrap; font-family: monospace; font-size: 0.85rem;"></div>
2026-04-27 19:01:18 +07:00
</div>
</div>
</div>
</div>
2026-04-27 18:57:25 +07:00
<script src="js/jquery-3.7.0.min.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<script src="js/dataTables.bootstrap5.min.js"></script>
2026-04-27 19:01:18 +07:00
<script src="js/bootstrap.bundle.min.js"></script>
2026-04-27 18:57:25 +07:00
<script>
$(document).ready(function () {
2026-04-27 19:04:47 +07:00
const TRUNCATE_LIMIT = 120;
2026-04-27 19:01:18 +07:00
2026-04-27 19:04:47 +07:00
const table = $('#log-table').DataTable({
dom: '<"d-flex justify-content-between mb-2"f>rtip',
2026-04-27 18:57:25 +07:00
columns: [
{
2026-04-27 19:01:18 +07:00
className: 'details-control',
orderable: false,
data: null,
2026-04-27 19:04:47 +07:00
render: (data, type, row) => row.exception ? '<i class="bi bi-chevron-right"></i>' : ''
2026-04-27 18:57:25 +07:00
},
2026-04-27 19:01:18 +07:00
{ data: 'time' },
{
data: 'level',
2026-04-27 19:04:47 +07:00
render: l => `<span class="badge-lvl bg-${l}">${l}</span>`
2026-04-27 19:01:18 +07:00
},
2026-04-27 18:57:25 +07:00
{
data: 'message',
2026-04-27 19:04:47 +07:00
render: function (data) {
if (data.length > TRUNCATE_LIMIT) {
return `<span class="text-truncate-custom">${data.substring(0, TRUNCATE_LIMIT)}</span><span class="btn-more" onclick="showFullLog('${btoa(unescape(encodeURIComponent(data)))}')">...more</span>`;
2026-04-27 19:01:18 +07:00
}
return data;
2026-04-27 18:57:25 +07:00
}
},
2026-04-27 19:01:18 +07:00
{
data: 'props',
2026-04-27 19:04:47 +07:00
render: p => `<span class="props-text">${p}</span>`
2026-04-27 19:01:18 +07:00
}
],
order: [[1, 'asc']],
2026-04-27 19:04:47 +07:00
language: { search: "", searchPlaceholder: "Quick search logs..." }
2026-04-27 18:57:25 +07:00
});
2026-04-27 19:04:47 +07:00
// Expand/Collapse Child Row
2026-04-27 19:01:18 +07:00
$('#log-table tbody').on('click', 'td.details-control', function () {
2026-04-27 19:04:47 +07:00
let tr = $(this).closest('tr');
let row = table.row(tr);
let icon = $(this).find('i');
2026-04-27 19:01:18 +07:00
if (row.child.isShown()) {
row.child.hide();
2026-04-27 19:04:47 +07:00
icon.attr('class', 'bi bi-chevron-right');
2026-04-27 19:01:18 +07:00
} else if (row.data().exception) {
2026-04-27 19:04:47 +07:00
row.child(`<div class="exception-wrapper">${row.data().exception}</div>`).show();
icon.attr('class', 'bi bi-chevron-down text-danger');
2026-04-27 19:01:18 +07:00
}
2026-04-27 18:57:25 +07:00
});
2026-04-27 19:04:47 +07:00
// Level Filter
$('#level-filter').on('change', function () {
table.column(2).search(this.value).draw();
2026-04-27 18:57:25 +07:00
});
2026-04-27 19:04:47 +07:00
// Drag and Drop Logic
const zone = $('#drop-zone');
zone.on('dragover', e => { e.preventDefault(); zone.addClass('dragover'); });
zone.on('dragleave', e => { zone.removeClass('dragover'); });
zone.on('drop', e => {
2026-04-27 19:01:18 +07:00
e.preventDefault();
2026-04-27 19:04:47 +07:00
zone.removeClass('dragover');
processFile(e.originalEvent.dataTransfer.files[0]);
2026-04-27 18:57:25 +07:00
});
2026-04-27 19:04:47 +07:00
$('#file-input').on('change', e => processFile(e.target.files[0]));
2026-04-27 18:57:25 +07:00
2026-04-27 19:04:47 +07:00
function processFile(file) {
2026-04-27 19:01:18 +07:00
if (!file) return;
2026-04-27 18:57:25 +07:00
const reader = new FileReader();
2026-04-27 19:01:18 +07:00
reader.onload = e => {
2026-04-27 19:04:47 +07:00
const data = parseLogFile(e.target.result);
table.clear().rows.add(data).draw();
2026-04-27 18:57:25 +07:00
};
reader.readAsText(file);
}
2026-04-27 19:04:47 +07:00
function parseLogFile(text) {
2026-04-27 18:57:25 +07:00
const lines = text.split(/\r?\n/);
2026-04-27 19:04:47 +07:00
const results = [];
// Header pattern: HH:mm:ss.SSS [LVL]
const headerRegex = /^(\d{2}:\d{2}:\d{2}\.\d{3})\s\[(\w+)\]\s(.*)$/;
2026-04-27 18:57:25 +07:00
lines.forEach(line => {
2026-04-27 19:03:12 +07:00
const trimmed = line.trim();
if (!trimmed) return;
2026-04-27 19:04:47 +07:00
const match = line.match(headerRegex);
if (match) {
let time = match[1];
let level = match[2];
let content = match[3].trim();
let message = content;
let props = "";
// Template: {message} ({props})
// Look for the last set of parentheses that contain a colon (key:value)
const lastOpenParen = content.lastIndexOf(' (');
if (lastOpenParen !== -1 && content.endsWith(')')) {
const potentialProps = content.substring(lastOpenParen + 2, content.length - 1);
if (potentialProps.includes(':')) {
props = potentialProps;
message = content.substring(0, lastOpenParen).trim();
}
2026-04-27 18:57:25 +07:00
}
2026-04-27 19:04:47 +07:00
results.push({ time, level, message, props, exception: "" });
2026-04-27 18:57:25 +07:00
} else {
2026-04-27 19:04:47 +07:00
// If line doesn't start with timestamp, it's an exception/stack trace
if (results.length > 0) {
results[results.length - 1].exception += (results[results.length - 1].exception ? "\n" : "") + line;
2026-04-27 18:57:25 +07:00
}
}
});
2026-04-27 19:04:47 +07:00
return results;
2026-04-27 18:57:25 +07:00
}
2026-04-27 19:04:47 +07:00
// Modal Helper
window.showFullLog = function (encoded) {
const text = decodeURIComponent(escape(atob(encoded)));
$('#modal-body-content').text(text);
new bootstrap.Modal('#logModal').show();
};
2026-04-27 18:57:25 +07:00
});
</script>
2026-04-27 19:04:47 +07:00
2026-04-27 18:57:25 +07:00
</body>
</html>