Skip to main content
Glama
simple-client.tsโ€ข4.46 kB
#!/usr/bin/env node import * as fs from 'fs/promises'; import { LogAnalyzer } from '../src/tools/logAnalyzer.js'; import { LogUtils } from '../src/utils.js'; class SimpleLogAnalyzerCLI { private logAnalyzer: LogAnalyzer; constructor() { this.logAnalyzer = new LogAnalyzer(); } async analyzeFile(filePath: string): Promise<void> { try { console.log(`๐Ÿ“– Analyzing log file: ${filePath}`); // Validate file exists await fs.access(filePath); // Read file content const content = await fs.readFile(filePath, 'utf-8'); console.log(`๐Ÿ“Š File size: ${(content.length / 1024).toFixed(2)} KB`); // Analyze the logs const analysis = await this.logAnalyzer.analyzeLogs(content, { logFormat: 'auto', contextLines: 50 }); this.displayAnalysisResult(analysis); } catch (error) { console.error('โŒ Failed to analyze file:', error); } } private displayAnalysisResult(analysis: any): void { console.log('\n๐Ÿ“‹ ANALYSIS RESULTS'); console.log('=================='); console.log(`๐ŸŽฏ Root Cause: ${analysis.rootCause}`); console.log(`๐Ÿ“Š Confidence: ${analysis.confidence}%`); console.log(`โš ๏ธ Severity: ${analysis.metadata.severity.toUpperCase()}`); console.log(`๐Ÿท๏ธ Error Type: ${analysis.metadata.errorType}`); if (analysis.suggestedFixes.length > 0) { console.log('\n๐Ÿ› ๏ธ SUGGESTED FIXES:'); analysis.suggestedFixes.forEach((fix: string, index: number) => { console.log(` ${index + 1}. ${fix}`); }); } if (analysis.relatedErrors.length > 0) { console.log('\n๐Ÿ”— RELATED ERRORS:'); analysis.relatedErrors.forEach((error: string, index: number) => { console.log(` ${index + 1}. ${error}`); }); } if (analysis.followUpQuestions.length > 0) { console.log('\nโ“ FOLLOW-UP QUESTIONS:'); analysis.followUpQuestions.forEach((question: string, index: number) => { console.log(` ${index + 1}. ${question}`); }); } if (analysis.metadata.stackTrace) { console.log('\n๐Ÿ“š STACK TRACE:'); console.log(analysis.metadata.stackTrace); } console.log(`\nโฐ Analysis completed at: ${new Date().toLocaleString()}`); } async testLogProcessing(sampleLog: string): Promise<void> { console.log('๐Ÿงช Testing log processing capabilities...\n'); // Test format detection const format = LogUtils.detectLogFormat(sampleLog); console.log(`๐Ÿ” Detected format: ${format}`); // Test error pattern extraction const errorPatterns = LogUtils.extractErrorPatterns(sampleLog); console.log(`๐Ÿšจ Found ${errorPatterns.length} error patterns`); // Test stack trace extraction const stackTraces = LogUtils.extractStackTraces(sampleLog); console.log(`๐Ÿ“š Found ${stackTraces.length} stack traces`); // Test content truncation const truncated = LogUtils.truncateContent(sampleLog, 1000); console.log(`โœ‚๏ธ Truncated content: ${truncated.length} characters`); console.log('\nโœ… Log processing test completed'); } } // CLI Entry point async function main() { const args = process.argv.slice(2); const cli = new SimpleLogAnalyzerCLI(); if (args.length === 0) { console.log('๐Ÿ“– Simple LogAnalyzer CLI'); console.log('Usage:'); console.log(' npm run analyze -- <file-path> - Analyze a log file'); console.log(' npm run analyze -- test - Run processing tests'); console.log('\nExample:'); console.log(' npm run analyze -- /var/log/app.log'); return; } const command = args[0]; if (command === 'test') { const sampleLog = ` 2024-01-23 10:30:15 ERROR: Database connection failed java.sql.SQLException: Connection is not available, request timed out after 30000ms. at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:154) at com.app.service.DatabaseService.connect(DatabaseService.java:45) at com.app.controller.UserController.getUser(UserController.java:78) 2024-01-23 10:30:16 FATAL: Application shutting down due to critical error 2024-01-23 10:30:17 ERROR: Failed to save user data `; await cli.testLogProcessing(sampleLog); } else { // Treat first argument as file path await cli.analyzeFile(command); } } if (import.meta.url === `file://${process.argv[1]}`) { main().catch(console.error); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ChiragPatankar/loganalyzer-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server