logkit 0.0.4 copy "logkit: ^0.0.4" to clipboard
logkit: ^0.0.4 copied to clipboard

A lightweight logging package for Flutter and Dart. Supports console and file logging with daily log rotation.

example/lib/main.dart

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]);
  }
}
1
likes
160
points
113
downloads

Publisher

unverified uploader

Weekly Downloads

A lightweight logging package for Flutter and Dart. Supports console and file logging with daily log rotation.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, hive, logger, path_provider

More

Packages that depend on logkit