Refactored log line parsing in parseLogLines function.

This commit is contained in:
Benjamin Arntzen
2024-06-27 07:29:31 +01:00
committed by Benjamin Arntzen (aider)
parent 5a026ab53a
commit 14a653a377
-18
View File
@@ -101,24 +101,6 @@ function parseLogLines(data) {
const logLines = data.split('\n');
const validLogs = [];
logLines.forEach((line, index) => {
if (line.trim() !== '') {
try {
const jsonLine = line.trim()
.replace(/(\w+)="(.*?)"/g, '"$1":"$2"') // Wrap keys and string values in double quotes
.replace(/,(\s*)(?![^{}]*\})/g, ',$1"') // Add double quotes around any keys that follow a comma and are not inside braces
.replace(/(\w+):/g, '"$1":') // Wrap unquoted keys in double quotes
.replace(/=\s*/g, ': '); // Replace equals sign with colon
const parsedLog = JSON.parse('{' + jsonLine + '}');
validLogs.push(parsedLog);
} catch (parseError) {
console.error(`Error parsing log line at index ${index}: ${parseError.message}`);
}
}
});
return validLogs;
if (typeof value === 'string') {
try {