316 lines
11 KiB
HTML
316 lines
11 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Log Viewer Pro</title>
|
|
<link href="css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="css/dataTables.bootstrap5.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
|
|
<style>
|
|
body {
|
|
background-color: #f8f9fa;
|
|
font-size: 0.82rem;
|
|
color: #333;
|
|
}
|
|
|
|
.container-fluid {
|
|
padding: 20px;
|
|
}
|
|
|
|
/* Drag & Drop */
|
|
#drop-zone {
|
|
border: 2px dashed #dee2e6;
|
|
background: #fff;
|
|
padding: 25px;
|
|
text-align: center;
|
|
border-radius: 12px;
|
|
cursor: pointer;
|
|
transition: all 0.2s ease;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
#drop-zone:hover,
|
|
#drop-zone.dragover {
|
|
border-color: #0d6efd;
|
|
background: #f0f7ff;
|
|
}
|
|
|
|
/* Table Styling */
|
|
.table-card {
|
|
background: #fff;
|
|
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;
|
|
}
|
|
|
|
.bg-INF {
|
|
background-color: #e3f2fd;
|
|
color: #0d6efd;
|
|
}
|
|
|
|
.bg-ERR {
|
|
background-color: #ffebee;
|
|
color: #c62828;
|
|
}
|
|
|
|
.bg-DBG {
|
|
background-color: #f5f5f5;
|
|
color: #616161;
|
|
}
|
|
|
|
.bg-TRC {
|
|
background-color: #f3e5f5;
|
|
color: #7b1fa2;
|
|
}
|
|
|
|
/* Child Row / Exception */
|
|
.details-control {
|
|
cursor: pointer;
|
|
color: #0d6efd;
|
|
font-size: 1rem;
|
|
}
|
|
|
|
.exception-wrapper {
|
|
background: #1e1e1e;
|
|
color: #dcdcdc;
|
|
padding: 15px;
|
|
border-radius: 6px;
|
|
font-family: 'Consolas', monospace;
|
|
font-size: 0.75rem;
|
|
white-space: pre-wrap;
|
|
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;
|
|
}
|
|
|
|
.btn-more {
|
|
color: #0d6efd;
|
|
text-decoration: underline;
|
|
cursor: pointer;
|
|
font-weight: 500;
|
|
margin-left: 5px;
|
|
}
|
|
|
|
.props-text {
|
|
color: #666;
|
|
font-style: italic;
|
|
font-size: 0.75rem;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="container-fluid">
|
|
<div id="drop-zone" onclick="document.getElementById('file-input').click()">
|
|
<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>
|
|
<input type="file" id="file-input" hidden accept=".log,.txt">
|
|
</div>
|
|
|
|
<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>
|
|
</select>
|
|
</div>
|
|
<div id="search-container"></div>
|
|
</div>
|
|
|
|
<table id="log-table" class="table table-hover table-sm w-100">
|
|
<thead>
|
|
<tr>
|
|
<th width="30"></th>
|
|
<th width="100">Timestamp</th>
|
|
<th width="60">Lvl</th>
|
|
<th>Message</th>
|
|
<th width="250">Properties</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody></tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="modal fade" id="logModal" tabindex="-1">
|
|
<div class="modal-dialog modal-lg">
|
|
<div class="modal-content">
|
|
<div class="modal-header py-2 px-3">
|
|
<h6 class="modal-title">Full Message Log</h6>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
<div class="modal-body bg-light">
|
|
<div id="modal-body-content"
|
|
style="white-space: pre-wrap; font-family: monospace; font-size: 0.85rem;"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<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>
|
|
<script src="js/bootstrap.bundle.min.js"></script>
|
|
|
|
<script>
|
|
$(document).ready(function () {
|
|
const TRUNCATE_LIMIT = 120;
|
|
|
|
const table = $('#log-table').DataTable({
|
|
dom: '<"d-flex justify-content-between mb-2"f>rtip',
|
|
columns: [
|
|
{
|
|
className: 'details-control',
|
|
orderable: false,
|
|
data: null,
|
|
render: (data, type, row) => row.exception ? '<i class="bi bi-chevron-right"></i>' : ''
|
|
},
|
|
{ data: 'time' },
|
|
{
|
|
data: 'level',
|
|
render: l => `<span class="badge-lvl bg-${l}">${l}</span>`
|
|
},
|
|
{
|
|
data: 'message',
|
|
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>`;
|
|
}
|
|
return data;
|
|
}
|
|
},
|
|
{
|
|
data: 'props',
|
|
render: p => `<span class="props-text">${p}</span>`
|
|
}
|
|
],
|
|
order: [[1, 'asc']],
|
|
language: { search: "", searchPlaceholder: "Quick search logs..." }
|
|
});
|
|
|
|
// Expand/Collapse Child Row
|
|
$('#log-table tbody').on('click', 'td.details-control', function () {
|
|
let tr = $(this).closest('tr');
|
|
let row = table.row(tr);
|
|
let icon = $(this).find('i');
|
|
|
|
if (row.child.isShown()) {
|
|
row.child.hide();
|
|
icon.attr('class', 'bi bi-chevron-right');
|
|
} else if (row.data().exception) {
|
|
row.child(`<div class="exception-wrapper">${row.data().exception}</div>`).show();
|
|
icon.attr('class', 'bi bi-chevron-down text-danger');
|
|
}
|
|
});
|
|
|
|
// Level Filter
|
|
$('#level-filter').on('change', function () {
|
|
table.column(2).search(this.value).draw();
|
|
});
|
|
|
|
// 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 => {
|
|
e.preventDefault();
|
|
zone.removeClass('dragover');
|
|
processFile(e.originalEvent.dataTransfer.files[0]);
|
|
});
|
|
$('#file-input').on('change', e => processFile(e.target.files[0]));
|
|
|
|
function processFile(file) {
|
|
if (!file) return;
|
|
const reader = new FileReader();
|
|
reader.onload = e => {
|
|
const data = parseLogFile(e.target.result);
|
|
table.clear().rows.add(data).draw();
|
|
};
|
|
reader.readAsText(file);
|
|
}
|
|
|
|
function parseLogFile(text) {
|
|
const lines = text.split(/\r?\n/);
|
|
const results = [];
|
|
// Header pattern: HH:mm:ss.SSS [LVL]
|
|
const headerRegex = /^(\d{2}:\d{2}:\d{2}\.\d{3})\s\[(\w+)\]\s(.*)$/;
|
|
|
|
lines.forEach(line => {
|
|
const trimmed = line.trim();
|
|
if (!trimmed) return;
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
results.push({ time, level, message, props, exception: "" });
|
|
} else {
|
|
// 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;
|
|
}
|
|
}
|
|
});
|
|
return results;
|
|
}
|
|
|
|
// Modal Helper
|
|
window.showFullLog = function (encoded) {
|
|
const text = decodeURIComponent(escape(atob(encoded)));
|
|
$('#modal-body-content').text(text);
|
|
new bootstrap.Modal('#logModal').show();
|
|
};
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html> |