Refactored log line parsing to transform into valid JSON format.
This commit is contained in:
@@ -101,37 +101,26 @@ function parseLogLines(data) {
|
||||
const logLines = data.split('\n');
|
||||
const validLogs = [];
|
||||
|
||||
|
||||
logLines.forEach((line, index) => {
|
||||
if (line.trim() !== '') {
|
||||
try {
|
||||
// Transform log line to valid JSON by replacing '=' with ':' and adding quotes around field names
|
||||
const jsonLine = line
|
||||
.replace(/(\w+)=/g, '"$1":')
|
||||
.replace(/"(\w+)":/g, (_, match) => `"${match}":`)
|
||||
.replace(/"(\w+)":/g, (_, match) => `"${match}":`)
|
||||
.replace(/(\w+):/g, '"$1":')
|
||||
.replace(/,(\s*})/g, '$1');
|
||||
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 {
|
||||
return JSON.parse(value);
|
||||
} catch (e) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
validLogs.push(parsedLog);
|
||||
} catch (parseError) {
|
||||
console.error(`Error parsing log line at index ${index}: ${parseError.message}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (typeof value === 'string') {
|
||||
try {
|
||||
return JSON.parse(value);
|
||||
} catch (e) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
validLogs.push(parsedLog);
|
||||
} catch (parseError) {
|
||||
console.error(`Error parsing log line at index ${index}: ${parseError.message}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return validLogs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user