err 0.8.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 78

Err #

pub package api doc

A logs router. The messages can be routed to:

  • Terminal
  • Flash messages
  • Snackbar messages

Configuration #

Configure the log levels's routes: available routes: console, screen, notifications or black hole. All the logs routed to the black hole will be silently swallowed: use it this to disable a route.

All routes default to console.

   import 'package:err/err.dart';

   var logger = ErrRouter(
      criticalRoute: [ErrRoute.console, ErrRoute.screen],
      errorRoute: [ErrRoute.screen, ErrRoute.console],
      warningRoute: [ErrRoute.screen, ErrRoute.console],
      infoRoute: [ErrRoute.screen],
      debugRoute: [ErrRoute.blackHole]);

Screen route #

Flash messages #

The flash messages are toast messages. They stay one second on the screen

   @override
   void initState() {
      logger.debugFlash("Init state");
       super.initState();
   }

Available flash messages:

infoFlash(String msg): an information message. Stays for 1 second on screen.

debugFlash(String msg): a debug message. Stays for 1 second on screen.

warningFlash(String msg): a warning message. Stays for 3 seconds on screen.

errorFlash(String msg): an error message. Stays for 5 seconds on screen.

flash(String msg): alias for debugFlash

Screenshot

Snackbar messages #

The snackbar messages need a BuildContext

   logger.infoScreen("File uploaded in $elapsed s", context: context);
   logger.debugScreen("A debug message", context: context);
   try {
      somethingWrong();
   } catch(ex) {
      logger.criticalScreen(
         err: ex,
         msg: "Something wrong happened",
         context: context);  
   }

Available messages #

criticalScreen(String msg, {@required BuildContext context, dynamic err})

errorScreen(String msg, {@required BuildContext context, dynamic err})

warningScreen(String msg, {@required BuildContext context,dynamic err, bool short})

infoScreen(String msg, {@required BuildContext context,dynamic err, bool short})

debugScreen(String msg, {@required BuildContext context,dynamic err, bool short})

Parameters: #

msg : a text message

err : an error or exception

short : if enabled the message will stay on screen for 5 seconds. If not it will stay until dismissed

context : the build context required for screen messages

Screenshot

Console route #

critical(String msg, {dynamic err})

error(String msg)

warning(String msg, {dynamic err})

info(String msg)

debug(String msg, {dynamic err})

Screenshot

By default the terminal output is configured for black and white. If your terminal supports colorized unicode emoticons use this parameter:

   var logger = ErrRouter(
      // ...
      terminalColors: true);

Screenshot

On device console #

A console log is available on the device. To enable it:

ErrRouter(
    // ...
    deviceConsole: true
)

Navigate to DeviceConsolePage(logger) to see the console on the device

Libraries used #

Changelog #

0.8.0 #

  • Add an errorFlash method
  • Add on device console option
  • Refactoring
  • Use pedantic for static anlytics

0.7.3 #

  • Add an errorFlash method

0.7.2 #

  • Fix the infoScreen short parameter
  • Set short messages duration to 5 seconds

0.7.1 #

Fix infoFlash and debugFlash

0.7.0 #

  • Breaking change: fix some functions in the api to be easier to use

  • Use more strict linting rules

0.6.0 #

Remove the notifications route to avoid permissions issues

0.5.0 #

Breaking change: the context parameter is now positionnal for the main methods

Feature: add the notification route

0.4.0 #

Add sync functions

0.3.0 #

Breaking change: the api has been simplified with a more efficient syntax

0.2.0 #

Improve the terminal output

0.1.0 #

Initial release

example/README.md

Example #

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Err example',
      home: MyHomePage(),
    );
  }
}

class _MyHomePageState extends State<MyHomePage> {

var logger = ErrRouter(
    criticalRoute: [ErrRoute.console, ErrRoute.screen],
    errorRoute: [ErrRoute.screen, ErrRoute.console],
    warningRoute: [ErrRoute.screen, ErrRoute.console],
    infoRoute: [ErrRoute.screen, ErrRoute.console],
    debugRoute: [ErrRoute.screen, ErrRoute.console]);

  @override
  void initState() {
    logger.debugFlash("Init state");
    super.initState();
  }

  bool firstBuildDone = false;

  @override
  Widget build(BuildContext context) {
    if (!firstBuildDone)
      logger.debugFlash("First build").then((_) {
        firstBuildDone = true;
      });
    return Scaffold(
        body: Padding(
            padding: EdgeInsets.all(25.0),
            child: ListView(
              children: <Widget>[
                RaisedButton(
                  child: Text("Info flash message"),
                  onPressed: () => logger.infoFlash("An info flash message"),
                ),
                RaisedButton(
                    child: Text("Info regular message"),
                    onPressed: () =>
                        logger.info("An info message", context: context)),
                RaisedButton(
                    child: Text("Warning message"),
                    onPressed: () => logger.warning("Hey, this is warning!",
                        context: context)),
                RaisedButton(
                    child: Text("Error message"),
                    onPressed: () =>
                        logger.error("Something went wrong", context: context)),
                RaisedButton(
                    child: Text("Critical message from exception"),
                    onPressed: () {
                      try {
                        _doWrong();
                      } catch (e) {
                        logger.criticalErr(
                            msg: "Something went really wrong",
                            err: e,
                            context: context);
                      }
                    }),
                RaisedButton(
                    child: Text("Debug message"),
                    onPressed: () =>
                        logger.debug("Debug info message", context: context)),
              ],
            )));
  }

  _doWrong() {
    List<String> li;
    li.add("wrong");
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  err: ^0.8.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:err/err.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
56
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
78
Learn more about scoring.

We analyzed this package on Nov 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
cupertino_icons ^0.1.2 0.1.2
flushbar ^1.8.2 1.9.1
flutter 0.0.0
fluttertoast ^3.1.0 3.1.3
logger ^0.7.0+2 0.7.0+2
pedantic ^1.7.0 1.8.0+1
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test