logkit 0.0.3
logkit: ^0.0.3 copied to clipboard
A lightweight logging package for Flutter and Dart. Supports console and file logging with daily log rotation.
LogKit ππ #
LogKit is a simple and efficient Flutter logging package that extends the popular logger package.
It supports console logging, persistent Hive-based storage, and log file export.
π Features #
β
Console Logging β Uses logger package for structured logging
β
Hive-based Log Storage β Stores logs persistently in Hive
β
Auto-delete Old Logs β Automatically removes the previous day's logs
β
Export Logs to a File β Export logs to a .log text file
β
Customizable Logging Levels β Supports debug, info, warning, error, and fatal logs
β
Works on Flutter & Dart β Supports both mobile and desktop platforms
π οΈ Getting Started #
1οΈβ£ Install the package #
Add logkit to your pubspec.yaml dependencies:
dependencies:
logkit: ^0.0.1 # Use the latest version
hive: ^2.2.3
path_provider: ^2.1.5
Run:
flutter pub get
π Usage #
1οΈβ£ Import LogKit #
import 'package:logkit/logkit.dart';
2οΈβ£ Initialize Logger #
Call this in main.dart before using logs:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final logger = UISLogger();
await logger.initialize(); // Initialize Hive storage before logging
runApp(const MyApp());
}
3οΈβ£ Log Messages #
logger.log("This is an info message"); // Default: Level.info
logger.log("Debugging details...", level: Level.debug);
logger.log("Something is wrong!", level: Level.warning);
logger.log("Critical Error!", level: Level.error);
4οΈβ£ Export Logs to a File #
logger.exportLogsToFile().then((path) {
print("Logs exported to: $path");
});
5οΈβ£ Fetch All Logs #
List<String> logs = logger.getAllLogs();
print("All Logs: $logs");
π― Example App #
Hereβs a simple Flutter app that logs messages when a button is clicked.
import 'package:flutter/material.dart';
import 'package:logkit/logkit.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final logger = UISLogger();
await logger.initialize(); // Initialize Hive before logging
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 & Export #
- Logs are persistently stored in Hive database.
- Previous day's logs are automatically deleted before inserting new logs.
- You can export logs to a
.logfile in the appβs document directory.
| Platform | Log Storage Location |
|---|---|
| Android / iOS | App documents directory (getApplicationDocumentsDirectory()) |
| macOS / Windows / Linux | User documents directory |
| Web | Not supported (logs only in console) |
π€ Contributing #
Want to improve LogKit? Contributions are welcome!
- Open an issue for bug reports & feature requests
- Submit a pull request with enhancements
π License #
This project is licensed under the MIT License.
See LICENSE for details.
π Enjoy logging with LogKit! π₯