flutter_log_processor 1.5.0
flutter_log_processor: ^1.5.0 copied to clipboard
A comprehensive Flutter package for logging, event tracking, and log preprocessing with an integrated dashboard.
Flutter Log Processor #
A comprehensive Flutter package for logging, event tracking, and log preprocessing with an integrated beautiful dashboard for visualization.
Features #
✨ Easy Integration - Simple API to add logging to any Flutter app
📊 Beautiful Dashboard - Premium UI for visualizing logs and events
🔍 Advanced Filtering - Search and filter logs by level, tag, date, and more
📈 Statistics & Analytics - Automatic log processing and pattern detection
⚡ Event Tracking - Track user events with timing and properties
💾 Persistent Storage - Logs and events are saved locally
📤 Export Functionality - Export logs as JSON, CSV, or text
🎨 Customizable - Themes and colors can be customized
Architecture #
[Flutter Log Processor Architecture]
The package is built with a clean, modular architecture featuring:
- LogService - Central logging hub with multiple severity levels
- EventTracker - Track user actions and system events
- LogDashboard - Beautiful UI for visualizing and analyzing logs
- Local Persistence - Secure local storage for all data
Dashboard Preview #
[Dashboard UI]
The integrated dashboard provides a comprehensive view of your app's logs and events with:
- Real-time statistics and metrics
- Color-coded log entries
- Interactive filtering and search
- Beautiful charts and visualizations
Installation #
Add this to your package's pubspec.yaml file:
dependencies:
flutter_log_processor: ^latest_version
Then run:
flutter pub get
Quick Start #
1. Initialize the Logger #
import 'package:flutter_log_processor/flutter_log_processor.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize the log service
await LogService().initialize(
userId: 'user123',
sessionId: 'session456',
enableConsoleOutput: true,
minimumLevel: LogLevel.verbose,
);
runApp(MyApp());
}
2. Add Logs #
// Simple logging
LogService().info('User logged in');
LogService().warning('Low memory warning');
LogService().error('Failed to load data',
tag: 'Network',
metadata: {'url': 'https://api.example.com'},
);
// With tags and metadata
LogService().debug('Cache hit',
tag: 'Cache',
metadata: {'key': 'user_profile', 'ttl': 3600},
);
3. Track Events #
// Initialize event tracker
await EventTracker().initialize(
userId: 'user123',
sessionId: 'session456',
);
// Track simple events
EventTracker().track('button_clicked',
category: 'interaction',
properties: {'button_name': 'login'},
);
// Track screen views
EventTracker().trackScreenView('HomeScreen');
// Track timed events
EventTracker().startTimedEvent('api_call');
// ... do work ...
EventTracker().endTimedEvent('api_call',
category: 'network',
properties: {'endpoint': '/api/users'},
);
4. Show Dashboard #
import 'package:flutter_log_processor/flutter_log_processor.dart';
// Navigate to the dashboard
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LogDashboard(
title: 'My App Logs',
primaryColor: Colors.purple,
),
),
);
Advanced Usage #
Custom Log Filtering #
final filter = LogFilter(
levels: {LogLevel.error, LogLevel.warning},
searchQuery: 'network',
startDate: DateTime.now().subtract(Duration(hours: 24)),
tag: 'API',
);
final logs = await LogService().getAllLogs();
final filtered = logs.where((log) => filter.matches(log)).toList();
Log Processing & Statistics #
final logs = await LogService().getAllLogs();
final stats = LogProcessor.processLogs(logs);
print('Total logs: ${stats.totalLogs}');
print('Errors: ${stats.errorsCount}');
print('Warnings: ${stats.warningsCount}');
// Find patterns (repeated errors)
final patterns = LogProcessor.findPatterns(logs);
for (final pattern in patterns) {
print('Pattern detected: $pattern');
}
Export Logs #
final logs = await LogService().getAllLogs();
// Export as JSON
final json = LogExporter.exportLogsAsJson(logs);
// Export as CSV
final csv = LogExporter.exportLogsAsCsv(logs);
// Export as text
final text = LogExporter.exportLogsAsText(logs);
// Save to file or share
Custom UI Components #
// Use individual viewers
LogViewer(
logs: myLogs,
showFilters: true,
onRefresh: () => _loadLogs(),
)
EventViewer(
events: myEvents,
onRefresh: () => _loadEvents(),
)
API Reference #
LogService #
The main service for logging.
Methods:
initialize()- Initialize the serviceverbose()- Log verbose messagedebug()- Log debug messageinfo()- Log info messagewarning()- Log warning messageerror()- Log error messagefatal()- Log fatal messagegetAllLogs()- Get all stored logsclearLogs()- Clear all logssetUserId()- Set user ID for logssetSessionId()- Set session ID for logs
EventTracker #
Service for tracking events.
Methods:
initialize()- Initialize the trackertrack()- Track an eventstartTimedEvent()- Start timing an eventendTimedEvent()- End timing an eventtrackScreenView()- Track screen viewtrackButtonClick()- Track button clickgetAllEvents()- Get all stored eventsclearEvents()- Clear all events
LogProcessor #
Utility for processing and analyzing logs.
Methods:
processLogs()- Generate statistics from logsprocessEvents()- Generate statistics from eventsfindPatterns()- Find repeated patterns in logsgroupLogsByPeriod()- Group logs by time period
LogDashboard #
Main dashboard widget.
Properties:
title- Dashboard titleshowLogs- Show logs tabshowEvents- Show events tabshowStatistics- Show statistics tabprimaryColor- Custom primary color
Example App #
import 'package:flutter/material.dart';
import 'package:flutter_log_processor/flutter_log_processor.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await LogService().initialize(userId: 'demo_user');
await EventTracker().initialize(userId: 'demo_user');
// Add some sample logs
LogService().info('App started');
LogService().debug('Initializing services', tag: 'Startup');
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Log Processor Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
useMaterial3: true,
),
home: DemoHomePage(),
);
}
}
class DemoHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Log Processor Demo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
// Add various logs
LogService().info('Info button pressed');
LogService().warning('Warning message', tag: 'Demo');
LogService().error('Error occurred',
tag: 'Demo',
metadata: {'timestamp': DateTime.now().toString()},
);
// Track event
EventTracker().trackButtonClick('demo_button');
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Logs and events added!')),
);
},
child: Text('Generate Sample Logs'),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LogDashboard(
title: 'My App Dashboard',
primaryColor: Colors.deepPurple,
),
),
);
},
child: Text('Open Dashboard'),
),
],
),
),
);
}
}
Screenshots #
The dashboard includes:
- 📊 Overview tab with statistics and charts
- 📝 Logs tab with filtering and search
- 🎯 Events tab with categorization
- 📤 Export functionality (JSON, CSV, Text)
- 🎨 Beautiful, modern UI design
Best Practices #
- Initialize early - Initialize services in
main()before running the app - Use tags - Tag logs for better organization and filtering
- Add metadata - Include relevant metadata for debugging
- Track meaningful events - Track user interactions and important app events
- Clean up periodically - Clear old logs to manage storage
- Set user context - Set userId and sessionId for better tracking
Performance #
- Logs are stored efficiently using SharedPreferences
- Maximum of 10,000 logs stored by default (configurable)
- Minimal performance impact on main thread
- Lazy loading in UI for smooth scrolling
License #
MIT License - see LICENSE file for details
Support #
For issues, feature requests, or questions, please file an issue on GitHub. Or contact me at syfalmjd11@gmail.com
Made with ❤️ by SaifAlmajd for the Flutter community