groveman 1.2.3 copy "groveman: ^1.2.3" to clipboard
groveman: ^1.2.3 copied to clipboard

Logging for Dart/Flutter applications, with the same concepts for tree and planting logging tree as Timber on Android

Groveman #

pub License: MIT groveman codecov

Logging for Dart/Flutter applications.

It's very similar to Android logging library called Timber and also with the package for Dart/Flutter called Fimber that implements the same concept of the tree and planting logging tree.

Behavior is added through Tree instances. You can install an instance by calling Groveman.plantTree. Installation of Trees should be done as early as possible, e.g, in the function main.

There are no Tree implementations installed by default because, second Timber, every time you log in production, a puppy dies.

There is a tree for the debug mode called DebugTree, it's totally configurable.

The logging is formed by the level, tag, message, extra, error and stack trace.

Levels #

For define severity of a logging. The level is set to one of five values, which are, in order of severity:

  • fatal
  • error
  • warning
  • info
  • debug

Usage #

Add it in your pubspec.yaml:

dependencies:
  groveman:

Import it where you want to use it e.g, in your main file.

import 'package:groveman/groveman.dart';

Initialize logging tree on start of your application.

void main(){
  Groveman.plantTree(DebugTree());

  //log
  Groveman.debug();
  Groveman.info('info', tag: 'info');
  Groveman.warning('error', tag: 'info', extra: <String, Object>{
      'name': 'Jungle',
      'trees': 50,
    },
  );
  Groveman.error('info', tag: 'info', error: Error());
  Groveman.fatal('info', tag: 'info', stackTrace: StackTrace.current);
}

You can plant a tree depending on the mode, e.g debug and production.

void main(){
  if (kReleaseMode) {
    Groveman.plantTree(CrashlyticsTree());
  } else {
    Groveman.plantTree(DebugTree());
  }
}

Configure to capture exception in Zone and in current Isolate

void main(){
  Groveman.captureErrorInZone(() => runApp(MyApp()));
  Groveman.captureErrorInCurrentIsolate();
}

Look at the example app to see Groveman in action.

Debug Tree #

Uses the dart:developer log() function to show logging.

It's only shown in debug mode, so there's no problem keeping DebugTree in production.

Format of the output

[Log Level] [tag]: message
extra
Error
StackTrace

output

The extra will be showed formatted as JSON.

If the tag is not provided, the implementation will automatically figure out from which file and line it's being called and use that file name and line as its tag. You can set to not show the tag.

Groveman.plantTree(DebugTree(showTag: false));

The log level text can be replaced for emoji.

Groveman.plantTree(DebugTree(showEmoji: true));

Sets method count, used when there is the stack trace.

// Log Level - debug, info, warning
Groveman.plantTree(DebugTree(methodCount: 2));
// Log Level - error, fatal
Groveman.plantTree(DebugTree(errorMethodCount: 2));

Still is possible to colorize your logs.

Groveman.plantTree(DebugTree(showColor: true));

There is a problem with the show of the stack trace in flutter web, you can see here https://github.com/flutter/flutter/issues/79176

Others officially supported Trees #

You can create your, just extend the Tree class. Take a look at the DebugTree code to know more.

📝 Maintainers #

Kauê Martins

🤝 Support #

You liked this package? Then give it a ⭐️. If you want to help then:

  • Fork this repository
  • Send a Pull Request with new features
  • Share this package
  • Create issues if you find a bug or want to suggest a new extension

Pull Request title follows Conventional Commits. The scope available is groveman.

📝 License #

Copyright © 2022 Kauê Martins.
This project is MIT licensed.

12
likes
150
pub points
70%
popularity

Publisher

verified publisherkmartins.dev

Logging for Dart/Flutter applications, with the same concepts for tree and planting logging tree as Timber on Android

Homepage
Repository (GitHub)
View/report issues

Topics

#logging #timber #report

Documentation

API reference

License

MIT (license)

Dependencies

meta

More

Packages that depend on groveman