logkit 0.0.4
logkit: ^0.0.4 copied to clipboard
A lightweight logging package for Flutter and Dart. Supports console and file logging with daily log rotation.
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:logkit/logkit.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final logger = UISLogger();
await logger.initializeHive(); // Initialize Hive before logging
logger.log("App started");
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: LoggerScreen(),
);
}
}
class LoggerScreen extends StatelessWidget {
const LoggerScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Logger Example")),
body: Center(
child: ElevatedButton(
onPressed: () {
_logRandomMessage();
},
child: const Text("Generate Random Log"),
),
),
);
}
void _logRandomMessage() {
final logger = UISLogger();
final random = Random();
// Define log levels
final levels = [
Level.debug,
Level.info,
Level.warning,
Level.error,
Level.fatal
];
final messages = [
"Debugging...",
"Info: User logged in",
"Warning: Low disk space",
"Error: Unable to fetch data",
"Fatal: System crash imminent"
];
int index = random.nextInt(levels.length);
logger.log(messages[index], level: levels[index]);
}
}