AILogStrategy class
AI Log Strategy for Strategic Logger
⚠️ SECURITY WARNING: This strategy sends logs to external AI services.
- Logs may contain sensitive data (tokens, passwords, personal information)
- Data is sent to third-party services (OpenAI, etc.)
- May generate API costs
- Ensure compliance with data privacy regulations (GDPR, LGPD, etc.)
Recommendations:
- Sanitize sensitive data before enabling
- Use with explicit user consent
- Consider data privacy implications
- Monitor API usage and costs
This strategy integrates with AI models and services to provide:
- Intelligent log analysis
- Pattern detection
- Anomaly detection
- Automated insights and recommendations
- Natural language log summaries
Example:
// Use with caution - understand data privacy implications
AILogStrategy(
apiKey: 'your-openai-api-key',
enableAnalysis: false, // Disabled by default
)
- Inheritance
-
- Object
- LogStrategy
- AILogStrategy
Constructors
Properties
- analysisTimer → Timer?
-
Analysis timer for testing
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
-
insightsStream
→ Stream<
AIInsight> -
Stream of AI insights
no setter
-
logBuffer
→ List<
AILogEntry> -
Log buffer for testing
no setter
- loggerLogLevel ↔ LogLevel
-
The log level set by the logger using this strategy. Used to determine if a message should be logged.
getter/setter pairinherited
- logLevel ↔ LogLevel
-
The minimum log level that this strategy handles for logging.
getter/setter pairinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
supportedEvents
↔ List<
LogEvent> ? -
A list of specific LogEvent types that this strategy supports. If null, all events are considered supported.
getter/setter pairinherited
Methods
-
buildAnalysisPrompt(
List< AILogEntry> entries) → String - Build analysis prompt for testing
-
buildContext(
Map< String, dynamic> ? additionalContext, StackTrace? stackTrace) → Map<String, dynamic> - Build context for testing
-
buildSystemPrompt(
) → String - Build system prompt for testing
-
determineInsightType(
AIAnalysisResult result) → AIInsightType - Determine insight type for testing
-
dispose(
) → void -
error(
LogEntry entry) → Future< void> -
Logs an error.
override
-
extractRecommendations(
String content) → List< String> - Extract recommendations for testing
-
fatal(
LogEntry entry) → Future< void> -
Logs a fatal error.
override
-
formatMessage(
dynamic message) → String - Format message for testing
-
generateLogId(
) → String - Generate log ID for testing
-
generateLogSummary(
{Duration? timeRange, int? maxLogs}) → Future< String> - Generates a summary of recent logs
-
info(
LogEntry entry) → Future< void> -
Logs an info message or event.
override
-
log(
LogEntry entry) → Future< void> -
Logs a message or event.
override
-
logError(
dynamic error, StackTrace? stackTrace, LogEvent? event, Map< String, dynamic> ? context) → Future<void> -
Legacy method for logging errors (for backward compatibility).
inherited
-
logMessage(
dynamic message, LogEvent? event, Map< String, dynamic> ? context) → Future<void> -
Legacy method for logging messages (for backward compatibility).
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
shouldLog(
{LogEvent? event}) → bool -
Determines whether a log operation should proceed based on the event and log level.
inherited
-
startAnalysis(
) → void - Starts the AI analysis timer
-
stopAnalysis(
) → void - Stops the AI analysis timer
-
toString(
) → String -
Provides a string representation of the strategy including its type and log level.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited