flutter_log_handler 0.1.0
flutter_log_handler: ^0.1.0 copied to clipboard
Enterprise-grade Flutter logging with console/file logs, crash capture, API interception, and built-in log viewer UI.
flutter_log_handler #
Enterprise-Grade Logging, Crash Tracking & API Monitoring Framework for Flutter
A production-ready logging infrastructure built specifically for modern Flutter applications.
Designed for enterprise apps, production builds, QA testing, white-label solutions, and scalable client deployments.
🚀 Why Use flutter_log_handler? #
print() is not production logging.
Modern Flutter apps require:
- ✅ Structured logs (info / warning / error)
- ✅ Persistent local storage with retention policy
- ✅ Crash capture & reporting
- ✅ API request/response tracking with performance monitoring
- ✅ Sensitive data masking (passwords, tokens, API keys)
- ✅ Enterprise-grade log viewer (search, filter, export)
- ✅ Shareable diagnostics for QA and supportExportable logs (TXT / JSON / PDF)
flutter_log_handler delivers a complete observability layer inside your Flutter application.
Lightweight. Configurable. Enterprise-ready.
🎯 Ideal Use Cases #
- Enterprise Flutter apps
- Production & QA builds
- API performance tracking & crash diagnostics
- White-label client deployments
- Large-scale apps requiring structured logs
🔥 Core Features #
| Feature | Description | Badge |
|---|---|---|
| Structured Logging | Log levels, timestamps, stack trace, route & API tracking, custom tags | 📝 |
| Crash Capture | Flutter errors, unhandled exceptions, async & zone errors, device metadata | 💥 |
| Hive Persistence | Local log storage with retention days & auto-cleanup | 🗂 |
| API Monitoring | Dio interceptor, slow API detection, masked request/response logging | 🌐 |
| Sensitive Data Masking | Auto-mask keys like password, token, apiKey | 🔐 |
| Log Viewer UI | Animated filter chips, real-time search, expandable stack traces, Pull-to-refresh, Pull-to-refresh, Copy log button, Share logs, Clean production-ready card UI |
🖥 |
| Export Logs | TXT / JSON / PDF, only today logs, grouped by date, customizable formats | 📤 |
| Session & Env Tags | Automatic session ID & environment (flavor, version, platform) tagging | 🛡 |
📦 Installation #
dependencies:
flutter_log_handler: ^0.1.0
Then run:
flutter pub get
⚙️ Quick Setup #
Initialize Logger in main() #
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Start session
SessionManager.startSession();
// Set environment tags
LogContext.setEnvironment(
flavor: "development",
appVersion: "0.0.6",
platform: "android",
);
// Initialize Hive log service
await LogServiceHive.init(
LogConfig(
retentionDays: 5,
enableConsoleLog: true,
sensitiveKeys: ["password", "token", "apiKey"],
),
);
runApp(const MyApp());
}
📝 Logging Examples #
Simple Log #
LogServiceHive.to.logEvent(
message: "User logged in",
level: LogLevel.info,
);
Log with Stack Trace #
LogServiceHive.to.logEvent(
message: error.toString(),
stackTrace: stack.toString(),
level: LogLevelHive.error,
);
Log with API Endpoint #
LogServiceHive.to.logEvent(
message: "API Failed",
level: LogLevel.error,
stackTrace: stack.toString(),
apiEndpoint: "/api/login",
);
Fetch Logs #
// Fetch all logs stored in Hive (latest first)
final logs = await LogServiceHive.to.getLogs();
// Example:
for (var log in logs) {
print("[${log.level.name.toUpperCase()}] ${log.timestamp}: ${log.message}");
}
💥 Crash Capture Setup #
await CrashWrapper.initialize(
logService: LogServiceHive.to,
);
Automatically captures:
- Flutter framework errors
- Unhandled async errors & Zone errors
- Device, platform, Session ID and environment tags
🌐 API Monitoring with Dio #
final dio = Dio();
dio.interceptors.add(
ApiInterceptor(LogServiceHive.to),
);
Logs:
- Request method & endpoint
- Request/response bodies (masked)
- Status & duration
- Slow API warnings
- API errors with stack traces
🖥 Open Log Viewer Screen #
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => LogViewerScreen(
title: "App Logs",
// Action buttons
enableShareButton: true,
enableRefreshButton: true,
enableClearButton: true,
// Search & filter
enableCollapsibleSearch: true,
showLevelChips: true,
enablePullToRefresh: true,
// Export system
enableCustomExportMenu: true,
allowedExportFormats: [
LogExportFormat.txt,
LogExportFormat.json,
LogExportFormat.pdf,
],
exportGroupByDate: true,
exportFormat: LogExportFormat.pdf,
),
),
);
#Features:
- Filter by log level
- Expand stack traces
- Refresh logs
- Share logs
- Enterprise UI design
📊 Configuration Options #
LogConfig(
retentionDays: 5,
enableConsoleLog: true,
sensitiveKeys: ["password", "secretKey"],
);
| Parameter | Description |
|---|---|
| retentionDays | Auto-delete logs older than X days |
| enableConsoleLog | Print logs in debug console |
| sensitiveKeys | Keys automatically masked to protect sensitive data |
📁 Log Storage Location #
- Hive stores logs in your app's internal storage:
ApplicationDocumentsDirectory / hive / app_logs
🛡 Architecture Highlights #
- Automatic route tracking
- Automatic crash tagging
- Session & environment tagging (SessionManager + LogContext)
- Enterprise filtering engine
- No dependency injection required
- Works with GetX or without it
- Easily extendable to cloud upload
- Modular production-ready architecture
- Safe for release builds
📈 SEO Keywords #
Flutter logger
Flutter crash logger
Flutter file logger
Flutter API interceptor
Flutter production monitoring
Flutter enterprise logging
Flutter monitoring framework
Flutter error tracking
Flutter debugging tool
Flutter performance monitoring
🏆 Designed for Production #
flutter_log_handler flutter_log_handler provides structured, production-safe logging for enterprise-grade Flutter apps.
📄 License #
MIT License
👨💻 Maintainer #
ASTR Raju
Enterprise Flutter Developer
GitHub: https://github.com/ASTR001