Giter Site home page Giter Site logo

hamedjafarzadeh / debugconsole-flutter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from drafakiller/debugconsole-flutter

0.0 1.0 0.0 13 KB

A console for debugging Flutter apps. Check the console for prints and errors, while you're testing it, all within your app. Make your own logging and check the StackTraces.

License: MIT License

Dart 100.00%

debugconsole-flutter's Introduction

Pub.dev package GitHub repository

Debug Console

A console for debugging Flutter apps, and displaying console messages on the widget.

Check the console for prints and errors, while you're testing it, all within your app. Make your own logging or watch for console prints.

Features

  • Log your messages
  • Display console messages and errors
  • Use different levels for better emphasis
  • Filter the logs
  • Add extra actions to execute from the Debug Console menu
  • Check StackTrace of errors

Getting started

Install it using pub:

flutter pub add debug_console

And import the package:

import 'package:debug_console/debug_console.dart';

Usage

A console can be created using the widget DebugConsole.

Each log message displays a timestamp, level, and stack trace, if available.

You can control the consoles using a DebugConsoleController, you can create your own to isolate a console from the others, or you can use the root, DebugConsole.instance.

final controller = DebugConsoleController();

controller.log('Hello World', level: DebugConsoleLevel.info);
print(controller.logs); // List<DebugControllerLog>
controller.clear();

DebugConsole.log('Hello World', level: DebugConsoleLevel.info);
DebugConsole.clear();

DebugConsole.info('Info message');
// Also: warning, error, fatal, debug

Log a message with a StackTrace, doesn't need to be an error, it works with any level.

DebugConsole.error('Error message', stackTrace: StackTrace.current);

Listen for Prints and Errors

To catch all messages in your app, you need to use DebugConsole.listen to listen for prints and errors.

Everything inside that function will be automatically logged.

DebugConsole.listen(() {
  runApp(const MyApp());
});
  • A controller can be given, instead of logging to the root.

Debug Console Popup

Run your app along with the Debug Console using the popup. Click the floating debug icon to open the console.

MaterialApp(
  home: DebugConsolePopup(
    showButton: true,
    child: ...
  );
);

Save logs to a file

In case you need the save the logs, when setting the savePath argument, it will automatically save all the logs to that file.

DebugConsole(
  savePath: 'debug_console.log',
);

For some platforms, using files can be a little bit more tricky:

  • When debugging on a desktop, like Windows, simple paths can be used to create a log file in the project folder.

  • When debugging on a mobile device, like Android and iOS, you need to use a storage/temporary path, the log files will stay on the device.

The Debug Console can automatically load the logs, using DebugConsole.loadPath, which should be set before using DebugConsole.instance. You can also manually load the logs when creating a controller.

Menu Actions

Actions can be added to the Debug Console to execute whenever needed from the menu.

DebutConsole(
  actions: [
    PopupMenuItem(
      onTap: () => print('test'),
      child: const Text('Print test'),
    ),
  ]
);

debugconsole-flutter's People

Contributors

drafakiller avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.