const fs = require('fs');
const path = require('path');
/**
* Strips metadata from log files.
* @param {string} filePath - The path to the log file.
* @param {string} outputFilePath - The path to save the metadata-stripped log file.
*/
function stripMetadata(filePath, outputFilePath) {
try {
const fileContent = fs.readFileSync(filePath, 'utf8');
let cleanedContent = '';
// Simple metadata removal: Remove lines starting with common metadata prefixes.
const metadataPrefixes = ['#', '[', '{', ' ', ' ', ' ', ' ', ' ']; // Add more prefixes as needed.
const lines = fileContent.split('\n');
for (const line of lines) {
let isMetadata = false;
for (const prefix of metadataPrefixes) {
if (line.startsWith(prefix)) {
isMetadata = true;
break;
}
}
if (!isMetadata) {
cleanedContent += line + '\n';
}
}
fs.writeFileSync(outputFilePath, cleanedContent, 'utf8');
console.log(`Metadata stripped from ${filePath} and saved to ${outputFilePath}`);
} catch (error) {
console.error(`Error processing ${filePath}: ${error.message}`);
}
}
module.exports = stripMetadata;
Add your comment