fix regex matching
This commit is contained in:
32
index.html
32
index.html
@@ -908,34 +908,30 @@
|
||||
// Try common log formats
|
||||
const patterns = [
|
||||
// 2024-01-15T10:23:45.123Z INFO message
|
||||
/^(\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?)\s+(DEBUG|INFO|WARN(?:ING)?|ERROR|FATAL|TRACE)\s+(.+)$/i,
|
||||
/^(?<time>\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?)\s+(?<lvl>DEBUG|INFO|WARN(?:ING)?|ERROR|FATAL|TRACE)\s+(?<msg>.+)$/i,
|
||||
// [2024-01-15 10:23:45] [INFO] message
|
||||
/^\[(\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d+)?)\]\s*\[(DEBUG|INFO|WARN(?:ING)?|ERROR|FATAL|TRACE)\]\s*(.+)$/i,
|
||||
/^\[(?<time>\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d+)?)\]\s*\[(?<lvl>DEBUG|INFO|WARN(?:ING)?|ERROR|FATAL|TRACE)\]\s*(?<msg>.+)$/i,
|
||||
// Jan 15 10:23:45 INFO message
|
||||
/^(\w{3}\s+\d{1,2}\s+\d{2}:\d{2}:\d{2})\s+(DEBUG|INFO|WARN(?:ING)?|ERROR|FATAL)\s+(.+)$/i,
|
||||
/^(?<time>\w{3}\s+\d{1,2}\s+\d{2}:\d{2}:\d{2})\s+(?<lvl>DEBUG|INFO|WARN(?:ING)?|ERROR|FATAL)\s+(?<msg>.+)$/i,
|
||||
// INFO 2024-01-15 10:23:45 message
|
||||
/^(DEBUG|INFO|WARN(?:ING)?|ERROR|FATAL)\s+(\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d+)?)\s+(.+)$/i,
|
||||
// 10:23:43.333 [INF] message
|
||||
/^(\d{2}:\d{2}:\d{2}\.\d{3})\s\[(INF|WRN|ERR|CRT|DBG|TRC)\]\s(.*)$/
|
||||
/^(?<lvl>DEBUG|INFO|WARN(?:ING)?|ERROR|FATAL)\s+(?<time>\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d+)?)\s+(?<msg>.+)$/i,
|
||||
// 10:23:43.333 [INF] message (props)
|
||||
/^(?<time>\d{2}:\d{2}:\d{2}\.\d{3})\s\[(?<lvl>INF|WRN|ERR|CRT|DBG|TRC)\]\s(?<msg>.*?)(?:\s\((?<props>".*?")\))?$/i
|
||||
];
|
||||
|
||||
let i = 0;
|
||||
//debugger
|
||||
debugger
|
||||
while (i < lines.length) {
|
||||
const line = lines[i].trim();
|
||||
let matched = false;
|
||||
for (const pat of patterns) {
|
||||
const m = line.match(pat);
|
||||
if (m) {
|
||||
const [, g1, g2, g3] = m;
|
||||
let timeStr, levelStr, msg;
|
||||
if (/^(DEBUG|INFO|WARN|ERROR|FATAL)/i.test(g1)) {
|
||||
timeStr = g2; levelStr = g1.toUpperCase().replace('WARNING', 'WARN'); msg = g3;
|
||||
} else {
|
||||
timeStr = g1; levelStr = g2.toUpperCase().replace('WARNING', 'WARN'); msg = g3;
|
||||
}
|
||||
levelStr = translateLogLevel(levelStr)
|
||||
let time
|
||||
let timeStr = m.groups.time || null
|
||||
let levelStr = translateLogLevel(m.groups.lvl || '')
|
||||
let msg = m.groups.msg || null
|
||||
let props = m.groups.props || null
|
||||
|
||||
if (filedate === null) {
|
||||
time = new Date(timeStr)
|
||||
}
|
||||
@@ -946,6 +942,7 @@
|
||||
}
|
||||
|
||||
if (!isNaN(time)) {
|
||||
|
||||
// Collect continuation lines (stack traces etc.)
|
||||
let exception = '';
|
||||
let j = i + 1;
|
||||
@@ -954,13 +951,14 @@
|
||||
if (cl) exception += (exception ? '\n' : '') + cl;
|
||||
j++;
|
||||
}
|
||||
|
||||
i = j - 1;
|
||||
logs.push({
|
||||
time,
|
||||
level: levelStr,
|
||||
message: msg.length > msg_len_limit ? msg.slice(0, msg_len_limit) + "..." : msg.trim(),
|
||||
fullmessage: msg.length > msg_len_limit ? msg : null,
|
||||
props: null,
|
||||
props: props,
|
||||
exception: exception || null
|
||||
});
|
||||
matched = true;
|
||||
|
||||
Reference in New Issue
Block a user