diff --git a/server.js b/server.js index 0acba4d..4a59ac6 100644 --- a/server.js +++ b/server.js @@ -105,24 +105,14 @@ function parseLogLines(data) { logLines.forEach((line, index) => { if (line.trim() !== '') { try { - let jsonLine = line.trim(); - // Replace the custom log format with valid JSON format - jsonLine = jsonLine.replace(/(\w+)="(.*?)"/g, '"$1":"$2"'); - jsonLine = `{${jsonLine}}`; - jsonLine = jsonLine.replace(/"(\w+)":{/g, '"$1":{'); - jsonLine = jsonLine.replace(/,(\w+):/g, ',"$1":'); - jsonLine = jsonLine.replace(/(\w+):/g, '"$1":'); - .replace(/=\{/g, ':{') // Replace ={ with :{ - .replace(/\}([,}])/g, '}$1') // Replace } with } at the end of objects - .replace(/=/g, '":') // Replace = with ": - .replace(/,(\S)/g, ',"$1') // Replace , with ," to separate fields - .replace(/(\w+):/g, '"$1":') // Add quotes around field names - .replace(/"(\w+)":{/g, '"$1":\{') // Ensure that nested objects have correct format - .replace(/(\w+)"(\w+)":/g, '$1"$2":') // Fix fields that may have been incorrectly split - .replace(/""/g, '\\"') // Escape double quotes inside strings - .replace(/(\w+):"/g, '"$1":"') // Ensure that all values are enclosed in double quotes - .replace(/(\w+)"(\w+)"/g, '$1"$2"') // Fix values that may have been incorrectly split - .replace(/""/g, '"'); // Remove any double double-quotes introduced by previous replacements + let jsonLine = line.trim() + .replace(/(\w+)="(.*?)"/g, '"$1":"$2"') // Replace key="value" with "key":"value" + .replace(/([,{])(\w+)=/g, '$1"$2":') // Add quotes around unquoted keys + .replace(/,(\w+):/g, ',"$1":') // Ensure commas are present between fields + .replace(/}(\w+):/g, '},"$1":'); // Ensure commas are present between nested objects + + // Parse the transformed JSON string + const parsedLog = JSON.parse(jsonLine); // Parse the transformed JSON string const parsedLog = JSON.parse('{' + jsonLine + '}');