generateLogSummary method

Future<String> generateLogSummary({
  1. Duration? timeRange,
  2. int? maxLogs,
})

Generates a summary of recent logs

Implementation

Future<String> generateLogSummary({Duration? timeRange, int? maxLogs}) async {
  try {
    final cutoffTime = timeRange != null
        ? DateTime.now().subtract(timeRange)
        : DateTime.now().subtract(const Duration(hours: 1));

    final recentLogs = _logBuffer
        .where((log) => log.timestamp.isAfter(cutoffTime))
        .take(maxLogs ?? 50)
        .toList();

    if (recentLogs.isEmpty) {
      return 'No recent logs found for the specified time range.';
    }

    final analysis = await _performAIAnalysis(recentLogs);

    if (analysis.isNotEmpty) {
      return analysis.first.summary;
    }

    return 'Generated summary: ${recentLogs.length} log entries analyzed.';
  } catch (e) {
    return 'Failed to generate log summary: $e';
  }
}