flutter_log_processor 1.5.0 copy "flutter_log_processor: ^1.5.0" to clipboard
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.

Version Flutter

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 service
  • verbose() - Log verbose message
  • debug() - Log debug message
  • info() - Log info message
  • warning() - Log warning message
  • error() - Log error message
  • fatal() - Log fatal message
  • getAllLogs() - Get all stored logs
  • clearLogs() - Clear all logs
  • setUserId() - Set user ID for logs
  • setSessionId() - Set session ID for logs

EventTracker #

Service for tracking events.

Methods:

  • initialize() - Initialize the tracker
  • track() - Track an event
  • startTimedEvent() - Start timing an event
  • endTimedEvent() - End timing an event
  • trackScreenView() - Track screen view
  • trackButtonClick() - Track button click
  • getAllEvents() - Get all stored events
  • clearEvents() - Clear all events

LogProcessor #

Utility for processing and analyzing logs.

Methods:

  • processLogs() - Generate statistics from logs
  • processEvents() - Generate statistics from events
  • findPatterns() - Find repeated patterns in logs
  • groupLogsByPeriod() - Group logs by time period

LogDashboard #

Main dashboard widget.

Properties:

  • title - Dashboard title
  • showLogs - Show logs tab
  • showEvents - Show events tab
  • showStatistics - Show statistics tab
  • primaryColor - 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 #

  1. Initialize early - Initialize services in main() before running the app
  2. Use tags - Tag logs for better organization and filtering
  3. Add metadata - Include relevant metadata for debugging
  4. Track meaningful events - Track user interactions and important app events
  5. Clean up periodically - Clear old logs to manage storage
  6. 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

1
likes
140
points
120
downloads

Publisher

verified publishersaifalmajd.blogspot.com

Weekly Downloads

A comprehensive Flutter package for logging, event tracking, and log preprocessing with an integrated dashboard.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, intl, path_provider, shared_preferences

More

Packages that depend on flutter_log_processor