rev1
This commit is contained in:
299
index.html
299
index.html
@@ -4,98 +4,118 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Log Parser & Viewer</title>
|
||||
<title>Compact Log Parser</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;
|
||||
padding: 20px;
|
||||
background-color: #f4f7f6;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
#drop-zone {
|
||||
border: 2px dashed #007bff;
|
||||
border-radius: 10px;
|
||||
padding: 40px;
|
||||
border: 2px dashed #0d6efd;
|
||||
background: #fff;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
background: white;
|
||||
transition: 0.3s;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
margin-bottom: 20px;
|
||||
transition: 0.2s;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
#drop-zone.dragover {
|
||||
background: #e7f1ff;
|
||||
border-color: #0056b3;
|
||||
}
|
||||
|
||||
.stack-trace {
|
||||
font-family: monospace;
|
||||
font-size: 0.85rem;
|
||||
color: #d63384;
|
||||
white-space: pre-wrap;
|
||||
display: block;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.lvl-ERR {
|
||||
color: #dc3545;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.lvl-INF {
|
||||
color: #0d6efd;
|
||||
}
|
||||
|
||||
.lvl-DBG {
|
||||
color: #6c757d;
|
||||
}
|
||||
|
||||
.lvl-TRC {
|
||||
color: #6610f2;
|
||||
#drop-zone:hover {
|
||||
background: #f0f7ff;
|
||||
}
|
||||
|
||||
.table-container {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
|
||||
background: #fff;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
/* Level Colors */
|
||||
.badge-ERR {
|
||||
background-color: #dc3545;
|
||||
}
|
||||
|
||||
.badge-INF {
|
||||
background-color: #0dcaf0;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.badge-DBG {
|
||||
background-color: #6c757d;
|
||||
}
|
||||
|
||||
.badge-TRC {
|
||||
background-color: #6610f2;
|
||||
}
|
||||
|
||||
/* Row styling */
|
||||
td.details-control {
|
||||
cursor: pointer;
|
||||
text-align: center;
|
||||
color: #0d6efd;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.exception-box {
|
||||
background: #fff5f5;
|
||||
border-left: 4px solid #dc3545;
|
||||
padding: 10px;
|
||||
font-family: monospace;
|
||||
font-size: 0.8rem;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.clickable-text {
|
||||
color: #0d6efd;
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.props-cell {
|
||||
max-width: 200px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-size: 0.75rem;
|
||||
color: #666;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="container-fluid">
|
||||
<h2 class="mb-4">Log File Parser</h2>
|
||||
|
||||
<div id="drop-zone">
|
||||
<h4>Drag & Drop log file here</h4>
|
||||
<p class="text-muted">or click to select a file</p>
|
||||
<input type="file" id="file-input" style="display: none;" accept=".log,.txt">
|
||||
<div class="container-fluid py-3">
|
||||
<div id="drop-zone" onclick="document.getElementById('file-input').click()">
|
||||
<strong><i class="bi bi-cloud-arrow-up"></i> Drop Log File Here</strong> or Click to Browse
|
||||
<input type="file" id="file-input" hidden accept=".log,.txt">
|
||||
</div>
|
||||
|
||||
<div class="table-container shadow-sm">
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Filter by Level</label>
|
||||
<select id="level-filter" class="form-select">
|
||||
<div class="table-container">
|
||||
<div class="d-flex gap-3 mb-3">
|
||||
<div style="width: 200px;">
|
||||
<select id="level-filter" class="form-select form-select-sm">
|
||||
<option value="">All Levels</option>
|
||||
<option value="INF">INF (Info)</option>
|
||||
<option value="ERR">ERR (Error)</option>
|
||||
<option value="DBG">DBG (Debug)</option>
|
||||
<option value="TRC">TRC (Trace)</option>
|
||||
<option value="INF">INF</option>
|
||||
<option value="ERR">ERR</option>
|
||||
<option value="DBG">DBG</option>
|
||||
<option value="TRC">TRC</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table id="log-table" class="table table-hover table-bordered w-100">
|
||||
<thead class="table-light">
|
||||
<table id="log-table" class="table table-sm table-hover w-100" style="border-top: 1px solid #dee2e6;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Time</th>
|
||||
<th>Level</th>
|
||||
<th>ID</th>
|
||||
<th>Tag</th>
|
||||
<th width="30"></th>
|
||||
<th width="100">Time</th>
|
||||
<th width="70">Level</th>
|
||||
<th width="50">Tag</th>
|
||||
<th>Message</th>
|
||||
<th>Properties</th>
|
||||
</tr>
|
||||
@@ -105,76 +125,113 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="logModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Full Log Detail</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div id="modal-content-text"
|
||||
style="white-space: pre-wrap; font-family: monospace; background: #f8f9fa; padding: 15px; border-radius: 5px;">
|
||||
</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 MAX_MSG_LEN = 80;
|
||||
|
||||
// DataTable Formatting Function for Child Row (Exceptions)
|
||||
function format(d) {
|
||||
if (!d.exception) return null;
|
||||
return `<div class="exception-box"><strong>Stack Trace:</strong><br>${d.exception}</div>`;
|
||||
}
|
||||
|
||||
let table = $('#log-table').DataTable({
|
||||
order: [[0, 'asc']],
|
||||
pageLength: 25,
|
||||
dom: '<"d-flex justify-content-between"lf>rtip',
|
||||
columns: [
|
||||
{ data: 'time', width: '10%' },
|
||||
{
|
||||
className: 'details-control',
|
||||
orderable: false,
|
||||
data: null,
|
||||
defaultContent: '',
|
||||
render: function (data, type, row) {
|
||||
return row.exception ? '<i class="bi bi-plus-square"></i>' : '';
|
||||
}
|
||||
},
|
||||
{ data: 'time' },
|
||||
{
|
||||
data: 'level',
|
||||
width: '5%',
|
||||
render: function (data) {
|
||||
return `<span class="lvl-${data}">${data}</span>`;
|
||||
}
|
||||
render: l => `<span class="badge badge-${l}">${l}</span>`
|
||||
},
|
||||
{ data: 'id', width: '5%' },
|
||||
{ data: 'tag', width: '8%' },
|
||||
{ data: 'tag' },
|
||||
{
|
||||
data: 'message',
|
||||
render: function (data) {
|
||||
// Split message and stack trace if exists
|
||||
const parts = data.split('\n');
|
||||
const mainMsg = parts.shift();
|
||||
const stack = parts.join('\n');
|
||||
return `<strong>${mainMsg}</strong>` + (stack ? `<span class="stack-trace">${stack}</span>` : '');
|
||||
render: function (data, type, row) {
|
||||
if (data.length > MAX_MSG_LEN) {
|
||||
return `${data.substr(0, MAX_MSG_LEN)}... <span class="clickable-text show-full" data-full="${btoa(unescape(encodeURIComponent(data)))}">[more]</span>`;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
},
|
||||
{ data: 'props', width: '20%' }
|
||||
]
|
||||
{
|
||||
data: 'props',
|
||||
className: 'props-cell',
|
||||
render: p => p ? `<span title="${p}">${p}</span>` : ''
|
||||
}
|
||||
],
|
||||
order: [[1, 'asc']],
|
||||
dom: 'ltipr'
|
||||
});
|
||||
|
||||
// Custom filtering for Log Level
|
||||
// Handle Click to Expand (Exception)
|
||||
$('#log-table tbody').on('click', 'td.details-control', function () {
|
||||
let tr = $(this).closest('tr');
|
||||
let row = table.row(tr);
|
||||
|
||||
if (row.child.isShown()) {
|
||||
row.child.hide();
|
||||
$(this).html('<i class="bi bi-plus-square"></i>');
|
||||
} else if (row.data().exception) {
|
||||
row.child(format(row.data())).show();
|
||||
$(this).html('<i class="bi bi-dash-square text-danger"></i>');
|
||||
}
|
||||
});
|
||||
|
||||
// Handle Click for Full Modal
|
||||
$('#log-table tbody').on('click', '.show-full', function () {
|
||||
const fullText = decodeURIComponent(escape(atob($(this).data('full'))));
|
||||
$('#modal-content-text').text(fullText);
|
||||
new bootstrap.Modal('#logModal').show();
|
||||
});
|
||||
|
||||
// Filtering logic
|
||||
$('#level-filter').on('change', function () {
|
||||
table.column(1).search(this.value).draw();
|
||||
table.column(2).search(this.value).draw();
|
||||
});
|
||||
|
||||
// File Handling
|
||||
const dropZone = $('#drop-zone');
|
||||
const fileInput = $('#file-input');
|
||||
|
||||
dropZone.on('click', () => fileInput.click());
|
||||
|
||||
dropZone.on('dragover', (e) => {
|
||||
// Drag & Drop / File Input
|
||||
$('#file-input').on('change', e => handleFile(e.target.files[0]));
|
||||
$('#drop-zone').on('dragover', e => { e.preventDefault(); $(this).addClass('bg-light'); });
|
||||
$('#drop-zone').on('drop', e => {
|
||||
e.preventDefault();
|
||||
dropZone.addClass('dragover');
|
||||
});
|
||||
|
||||
dropZone.on('dragleave', () => dropZone.removeClass('dragover'));
|
||||
|
||||
dropZone.on('drop', (e) => {
|
||||
e.preventDefault();
|
||||
dropZone.removeClass('dragover');
|
||||
const file = e.originalEvent.dataTransfer.files[0];
|
||||
if (file) handleFile(file);
|
||||
});
|
||||
|
||||
fileInput.on('change', (e) => {
|
||||
if (e.target.files[0]) handleFile(e.target.files[0]);
|
||||
handleFile(e.originalEvent.dataTransfer.files[0]);
|
||||
});
|
||||
|
||||
function handleFile(file) {
|
||||
if (!file) return;
|
||||
const reader = new FileReader();
|
||||
reader.onload = function (e) {
|
||||
const content = e.target.result;
|
||||
const parsedData = parseLogs(content);
|
||||
table.clear().rows.add(parsedData).draw();
|
||||
reader.onload = e => {
|
||||
const logs = parseLogs(e.target.result);
|
||||
table.clear().rows.add(logs).draw();
|
||||
};
|
||||
reader.readAsText(file);
|
||||
}
|
||||
@@ -182,37 +239,33 @@
|
||||
function parseLogs(text) {
|
||||
const lines = text.split(/\r?\n/);
|
||||
const logs = [];
|
||||
// Regex to match: Time [LVL] ID | (TAG) Message (PROPS)
|
||||
const logHeaderRegex = /^(\d{2}:\d{2}:\d{2}\.\d{3})\s\[(\w+)\]\s(\d+)\s\|\s\((.*?)\)\s(.*)$/;
|
||||
const headerRegex = /^(\d{2}:\d{2}:\d{2}\.\d{3})\s\[(\w+)\]\s(\d+)\s\|\s\((.*?)\)\s(.*)$/;
|
||||
|
||||
lines.forEach(line => {
|
||||
if (!line.trim()) return;
|
||||
|
||||
const match = line.match(logHeaderRegex);
|
||||
const match = line.match(headerRegex);
|
||||
|
||||
if (match) {
|
||||
let messagePart = match[5];
|
||||
let msg = match[5];
|
||||
let props = "";
|
||||
|
||||
// Extract props inside parentheses at the end of the line
|
||||
const propMatch = messagePart.match(/\(([^)]+:[^)]+)\)$/);
|
||||
const propMatch = msg.match(/\((idtask:.*)\)$/);
|
||||
if (propMatch) {
|
||||
props = propMatch[1];
|
||||
messagePart = messagePart.replace(propMatch[0], "").trim();
|
||||
msg = msg.replace(propMatch[0], "").trim();
|
||||
}
|
||||
|
||||
logs.push({
|
||||
time: match[1],
|
||||
level: match[2],
|
||||
id: match[3],
|
||||
tag: match[4],
|
||||
message: messagePart,
|
||||
props: props
|
||||
message: msg,
|
||||
props: props,
|
||||
exception: ""
|
||||
});
|
||||
} else {
|
||||
// If it doesn't match the header, it's likely a stack trace or multi-line message
|
||||
// It's a stack trace / exception line
|
||||
if (logs.length > 0) {
|
||||
logs[logs.length - 1].message += "\n" + line.trim();
|
||||
logs[logs.length - 1].exception += line + "\n";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user