LogKit ππ
LogKit is a lightweight, powerful, and production-ready Flutter logging package that extends the popular logger package.
It supports console logging, Hive-based persistent storage, and log exportingβon both native and web platforms.
π Features
β
Console Logging with the logger package
β
Persistent Log Storage using Hive (Filesystem on native, IndexedDB on Web)
β
Auto-delete logs from previous day to prevent bloat
β
Export logs to a .log file (native) or download as .log (web)
β
Supports all major log levels: debug, info, warning, error, fatal
β
Compatible with Android, iOS, Windows, macOS, Linux, and Web (WASM)
π οΈ Getting Started
1οΈβ£ Add Dependency
In your pubspec.yaml:
dependencies:
logkit: ^1.0.0 # Use the latest version
hive: ^2.2.3
path_provider: ^2.1.5
Then run:
flutter pub get
π Usage
πΉ Import LogKit
import 'package:logkit/logkit.dart';
πΉ Initialize Logger
Call initialize() before logging anything:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final logger = UISLogger();
await logger.initialize(); // Required for Hive setup
runApp(const MyApp());
}
πΉ Log Messages
logger.log("This is an info message"); // Default level: info
logger.log("Debugging details...", level: Level.debug);
logger.log("Warning message!", level: Level.warning);
logger.log("Something went wrong!", level: Level.error);
πΉ Export Logs
π₯οΈ On native platforms:
String path = await logger.exportLogsToFile();
print("Logs exported to: $path");
π On web:
await logger.exportLogsToWebDownload(); // Triggers browser download
πΉ Get All Logs
List<String> logs = logger.getAllLogs();
logs.forEach(print);
π― Example App
import 'package:flutter/material.dart';
import 'package:logkit/logkit.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final logger = UISLogger();
await logger.initialize();
logger.log("App started!");
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text("LogKit Example")),
body: Center(
child: ElevatedButton(
onPressed: () {
final logger = UISLogger();
logger.log("Button clicked!", level: Level.info);
},
child: const Text("Log Message"),
),
),
),
);
}
}
π Log Storage Details
| Platform | Storage Mechanism | Export Support |
|---|---|---|
| Android / iOS | Hive in app document dir | Yes β via File |
| Windows / macOS / Linux | Hive in user directory | Yes β via File |
| Web (WASM) | Hive in IndexedDB | Yes β via browser download |
π€ Contributing
We welcome contributions!
- β Report bugs via GitHub issues
- β Submit PRs for improvements
- β Help us improve support for new platforms or features
π License
This project is licensed under the MIT License. See LICENSE for full details.
π Start logging like a pro with LogKit! π₯ Lightweight. Flexible. Cross-platform.