// Name: Log Analyzer // Description: Analyzes a log file for errors and patterns. // Author: johnlindquist import '@johnlindquist/kit'; // Prompt the user to select a log file const logFile = await path({ placeholder: 'Select a log file' }); // Read the content of the selected log file const logContent = await readFile(logFile, 'utf-8'); // Define a regular expression to identify error lines (case-insensitive) const errorRegex = /error|exception|fail/i; // Filter log lines to find those containing errors const errorLines = logContent.split('\n').filter(line => errorRegex.test(line)); // Prompt the user to enter a pattern to search for const pattern = await arg({ placeholder: 'Enter a pattern to search for' }); // Create a regular expression from the user-provided pattern const patternRegex = new RegExp(pattern); // Filter log lines to find those matching the pattern const patternLines = logContent.split('\n').filter(line => patternRegex.test(line)); // Generate a summary of the log analysis const summary = ` # Log Analysis Report ## Log File: ${logFile} ## Error Summary: ${errorLines.length} errors found ${errorLines.join('\n')} ## Pattern Summary: ${patternLines.length} lines found matching "${pattern}" ${patternLines.join('\n')} `; // Display the summary in a stylized format await div(md(summary));