flutter_log_handler 0.0.5
flutter_log_handler: ^0.0.5 copied to clipboard
Enterprise-grade logging solution for Flutter applications. Provides console logging, file persistence, crash capturing, Dio API interception, retention control, and a built-in professional 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, admin dashboards, and scalable client deployments.
๐ Why flutter_log_handler? #
print() is not production logging.
Modern Flutter apps require:
- Structured logging
- Persistent log storage
- Crash monitoring
- API request/response tracking
- Slow API detection
- Secure data masking
- Log retention management
- Professional internal log viewer
- Shareable diagnostics for QA
flutter_log_handler delivers a complete observability layer inside your Flutter application.
Lightweight. Configurable. Enterprise-ready.
๐ฏ Ideal For #
- Enterprise Flutter applications
- Production monitoring
- QA builds
- Internal admin tools
- Crash diagnostics
- API performance tracking
- White-label client deployments
- Large-scale apps requiring structured logs
๐ฅ Core Features #
๐ Structured Logging System #
- Log levels:
info,warning,error - Timestamp tracking
- Route tracking
- API endpoint tracking
- Stack trace support
- Custom tags support
๐ File-Based Log Persistence #
- Stores logs locally
- Configurable directory name
- Configurable file name
- Secure storage inside app documents directory
๐ง In-Memory Log Store #
- Fast access without file read
- Efficient filtering
- High-performance UI rendering
- Controlled max log limit
๐ฅ Automatic Crash Capture #
Captures:
- Flutter framework errors
- Unhandled runtime exceptions
- Async errors
- Zoned errors
Now supports automatic crash tagging with:
- Device info
- Platform
๐ Dio API Interceptor #
Automatically logs:
- HTTP method
- API endpoint
- Request body (sanitized)
- Response body (sanitized)
- Status code
- API duration
- Slow APIs
- Error stack traces
Built-in slow API detection threshold.
๐ Sensitive Data Masking #
Automatically masks sensitive keys such as:
- password
- token
- accessToken
- refreshToken
- authorization
- apiKey
Customizable via configuration.
Prevents leaking sensitive data in production logs.
๐ฅ Professional Log Viewer UI #
Built-in enterprise log screen with:
- Level filtering
- Expandable stack traces
- Pull-to-refresh
- Share logs
- Clean card-based UI
- Production-friendly design
๐งน Retention & Storage Control #
- Maximum log count control
- Retention days support
- Auto-deletes old logs
- File rotation ready architecture
๐ฆ Installation #
dependencies:
flutter_log_handler: ^0.0.5
Then run:
flutter pub get
โ๏ธ Quick Setup #
1๏ธโฃ Initialize Logger in main() #
void main() async {
WidgetsFlutterBinding.ensureInitialized();
LogService.init(
const LogConfig(
maxLogs: 1000,
retentionDays: 7,
enableConsoleLog: true,
enableFileLog: true,
fileName: "app_logs.txt",
directoryName: "logs",
sensitiveKeys: ["password", "secretKey"],
),
);
await LogService.to.getLogs();
runApp(const MyApp());
}
๐ Logging Anywhere in Your App #
LogService.to.logEvent(
message: "User logged in",
level: LogLevel.info,
);
With Stack Trace #
LogService.to.logEvent(
message: error.toString(),
level: LogLevel.error,
stackTrace: stack.toString(),
);
With API Endpoint Tracking #
LogService.to.logEvent(
message: "API Failed",
level: LogLevel.error,
stackTrace: stack.toString(),
apiEndpoint: "/api/login",
);
๐ฅ Crash Capture Setup #
await CrashWrapper.initialize(
logService: LogService.to,
);
Automatically captures:
- Flutter framework errors
- Unhandled async errors
- Zone errors
- Device & platform metadata
๐ API Monitoring with Dio #
final dio = Dio();
dio.interceptors.add(
ApiInterceptor(LogService.to),
);
Logs:
- Request method
- Endpoint
- Request body (masked)
- Response status
- Duration
- Slow API warnings
- API errors with stack traces
๐ฅ Open Log Viewer Screen #
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => MyLogScreen(
title: "App Logs",
appBarColor: Colors.teal,
centerTitle: true,
// Custom AppBar icons and actions
leadingIcon: const Icon(Icons.arrow_back),
leadingIconOnTap: () => Navigator.pop(context),
refreshIcon: const Icon(Icons.refresh_outlined),
refreshOnTap: () => print("Logs refreshed"),
shareIcon: const Icon(Icons.share),
shareOnTap: LogService.to.shareLogs,
deleteIcon: const Icon(Icons.delete_forever),
deleteOnTap: () => print("Delete clicked"),
// Delete dialog text
deleteDialogTitle: "Confirm Delete",
deleteDialogMessage: "Do you want to clear all logs?",
deleteDialogConfirmText: "Yes, Delete",
deleteDialogCancelText: "Cancel",
// Log list and chips
showChipIndicator: true,
levelColors: {
LogLevel.info: Colors.blue,
LogLevel.warning: Colors.orange,
LogLevel.error: Colors.red,
},
noLogsMessage: "No logs found",
dateFormat: "EEE, MMM dd yyyy hh:mm a",
),
),
);
#Features:
- Filter by log level
- Expand stack traces
- Refresh logs
- Share logs
- Enterprise UI design
๐ Configuration Options #
LogConfig(
maxLogs: 500,
retentionDays: 5,
enableConsoleLog: true,
enableFileLog: true,
fileName: "app_logs.txt",
directoryName: "logs",
sensitiveKeys: ["password", "secretKey"],
);
| Parameter | Description |
|---|---|
| maxLogs | Maximum logs stored in memory |
| retentionDays | Auto-delete logs older than X days |
| enableConsoleLog | Print logs in debug console |
| enableFileLog | Persist logs to file |
| fileName | Log file name |
| directoryName | Folder inside app documents |
| sensitiveKeys | Keys automatically masked to protect sensitive data |
๐ Log Storage Location #
ApplicationDocumentsDirectory / directoryName / fileName
Example:
/data/user/0/com.example.app/documents/logs/app_logs.txt
๐ก Architecture Highlights #
- Singleton-based LogService
- No dependency injection required
- Works with GetX or without it
- Easily extendable to cloud upload
- Enterprise-grade modular structure
- Production-safe logging behavior
๐ 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 is built for teams that require reliability, observability, structured diagnostics, and production-safe logging inside Flutter applications.
If you're building serious apps โ this package is built for you.
๐ License #
MIT License
๐จโ๐ป Maintainer #
ASTR Raju
Enterprise Flutter Developer
GitHub: https://github.com/ASTR001