flutter_vault_logger

Secure, encrypted on-device crash log storage for Flutter apps.

Features

  • AES-256 encrypted export / import of crash logs
  • Hive-backed persistent local storage
  • Automatic device info & app version capture
  • Named report management (save, load, share)
  • Duplicate log detection and deduplication
  • Auto-clear after export (configurable expiry window)

Setup

1. Add the dependency

dependencies:
  flutter_vault_logger: ^0.1.3

2. Initialise in main()

import 'package:flutter/material.dart';
import 'package:flutter_vault_logger/flutter_vault_logger.dart';
import 'package:hive_flutter/hive_flutter.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Hive.initFlutter();

  await CrashLogService.init(
    const VaultLoggerConfig(
      encryptionKey: 'YourApp32CharKeyHere!!!!12345678', // exactly 32 chars
      encryptionIV: 'YourApp16CharIV!', // exactly 16 chars
      fileExtension: 'myapp', // exported files use .myapp extension
    ),
  );

  runApp(const MyApp());
}

3. Log errors

try {
  // ...
} catch (e, st) {
  await CrashLogService.logError(
    e,
    stackTrace: st,
    context: 'MyWidget.someMethod',
  );
}

Example app

A full runnable demo app is included in the example/ folder.

cd example
flutter pub get
flutter run

The example targets current Flutter Android/iOS tooling (Gradle 9 / AGP 9, SPM on iOS).

Configuration (VaultLoggerConfig)

Parameter Default Description
encryptionKey required 32-char AES-256 key
encryptionIV required 16-char AES IV
fileExtension vaultlog Extension of exported encrypted files
maxLogCount 100 Max logs kept before oldest is evicted
expirationMinutes 30 Minutes after export before auto-clear (0 = disabled)
onError null Optional error callback (defaults to debugPrint)

Key API

// Logging
await CrashLogService.logError(
  error,
  stackTrace: stackTrace,
  context: 'context label',
  logStackTraceIfNull: true,
);

// Reading
List<CrashLogModel> logs = CrashLogService.getLogs();

// Export / import
String path = await CrashLogService.exportEncryptedLogs();
List<CrashLogModel> imported = await CrashLogService.importEncryptedLogs(path);

// Reports
await CrashLogService.saveReport('User A – Issue 1', logs);
List<CrashReportModel> reports = CrashLogService.getReports();

// Duplicate detection
Map<String, List<CrashLogModel>> dupes = CrashLogService.findDuplicates(logs);
List<CrashLogModel> cleaned = CrashLogService.deduplicateLogs(logs);

License

MIT