app_monitor 1.0.3
app_monitor: ^1.0.3 copied to clipboard
App monitoring lib for logging and error handling.
AppMonitor - Flutter Error Monitoring & Logging Library #
A comprehensive error monitoring and logging solution for Flutter applications that helps developers track, record, and manage errors efficiently with local SQLite storage and customizable error handling.
Features β¨ #
- π Automatic Error Capturing - Catches all Flutter framework errors and Dart runtime errors
- πΎ Persistent Storage - SQLite database for reliable error log persistence
- π Detailed Error Reports - Captures error messages, stack traces, and timestamps
- β‘ Performance Optimized - Lightweight and non-blocking error recording
- π‘οΈ Crash Prevention - Optional prevention of app crashes from uncaught exceptions
- οΏ½ Custom Error Handling - Add your own error handling logic
- π Log Management - View, filter, and delete error logs
- π§© Easy Integration - Simple setup with powerful results
- π Navigator Integration - Built-in global navigator key for error dialogs
Installation π» #
Add the dependency to your pubspec.yaml
:
dependencies:
app_monitor: ^1.0.3
Usage π #
import 'package:app_monitor/app_monitor.dart';
void main() async {
// Ensure Flutter binding is initialized
WidgetsFlutterBinding.ensureInitialized();
final scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
final appMonitor = AppMonitor();
// Initialize AppMonitor
await appMonitor.initialize(
appName: 'MyApp',
onError: (error, stack) {
debugPrint('Stack: $stack');
scaffoldMessengerKey.currentState?.showSnackBar(
SnackBar(content: Text(error)),
);
},
);
// Run the app
runApp(
MyApp(scaffoldMessengerKey: scaffoldMessengerKey, appMonitor: appMonitor),
);
}
Methods #
/// Retrieves all error logs from database, sorted by most recent
Future<List<Map<String, dynamic>>> getAllLogs() async {
return await _db.query('logs', orderBy: 'timestamp DESC');
}
/// Clears all error logs from the database
///
/// Returns:
/// Number of records deleted
Future<int> deleteAllLogs() async {
return await _db.delete('logs');
}
/// Deletes a specific error log by its ID
///
/// Parameters:
/// - id: The ID of the log record to delete
///
/// Returns:
/// Number of records deleted (0 or 1)
Future<int> deleteLog(int id) async {
return await _db.delete('logs', where: 'id = ?', whereArgs: [id]);
}
License π #
MIT License
Copyright (c) 2025 Ferid Cafer