log_collector 1.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 61

Dart Log Collector #

pub package

Provides log filtering, buffering, and retry.

Inspired by cookpad/Puree-Swift.

Usage #

Define your own Filter/Output #

Filter #

Filter converts Log to List<Log>.

You can increase the log, transform it, or empty it.

class ActionFilter extends Filter {
  ActionFilter({String tagPattern}) : super(tagPattern: tagPattern);

  List<Log> transform(Log log) {
    final target = log.payload['target'];
    final type = log.payload['type'];
    if (target is! String || type is! String) {
      return [];
    } else {
      final properties = Map.of(log.payload)..remove('type');
      return [
          tag: 'ga.action',
          payload: {
            'event_name': type,
            'properties': properties,
          tag: 'my.action',
          payload: {
            'event_name': '${type}_$target',
            'properties': Map.of(properties)..remove('target'),

Output #

Output does not provide buffering and retrying.

The following PrintOutput will output logs to the console.

class PrintOutput extends Output {
  PrintOutput({String tagPattern}) : super(tagPattern: tagPattern);

  void emit(Log log) {
    print('${log.loggedAt}:[${log.tag}] ${log.payload}');

BufferedOutput #

BufferedOutput provide buffering and retrying.

class MyLogOutput extends BufferedOutput {
    String tagPattern,
    int flushInterval = 100,
    int retryLimit = 3,
    int logCountLimit = 5,
  }) : super(
            tagPattern: tagPattern,
            logStorage: FileLogStorage(),
            flushInterval: flushInterval,
            retryLimit: retryLimit,
            logCountLimit: logCountLimit);

  Future<bool> write(List<Log> logs) async {
    // TODO: send logs to your server.
    return Future<bool>.delayed(Duration(milliseconds: 50), () {
      logs.forEach((log) {
        final eventName = log.payload['event_name'];
        final properties = log.payload['properties'];
        print('🥝[MyLog] ${log.loggedAt}:[$eventName] $properties');
      // if return false, retrying.
      return true;

Make logger #

Only Filter and Output that match TagPattern are used.

final logger = Logger(
  filters: [
    PageViewFilter(tagPattern: 'page'),
    ActionFilter(tagPattern: 'action'),
  outputs: [
    PrintOutput(tagPattern: '**'),
    MyLogOutput(tagPattern: 'my.**'),
    AnalyticsOutput(tagPattern: 'ga.**'),

Post log #

logger.post({'name': 'page1'}, tag: 'page_view');
logger.post({'type': 'click', 'target': 'event_button'}, tag: 'action');

TagPattern matching. #

expect(TagPattern('aa.bb.cc').match('aa.bb.cc'), true);
expect(TagPattern('aa.bb.cc').match('aa.bb.dd'), false);
expect(TagPattern('aa.bb.cc').match('aa.bb'), false);
expect(TagPattern('aa.bb.cc').match('aa.bb.cc.dd'), false);

expect(TagPattern('aa.bb.*').match('aa.bb.cc'), true);
expect(TagPattern('aa.bb.*').match('aa.bb.cc.dd'), false);
expect(TagPattern('aa.bb.*').match('aa.bb'), false);

expect(TagPattern('aa.**').match('aa.bb.cc'), true);
expect(TagPattern('aa.**').match('aa.bb.cc.dd'), true);
expect(TagPattern('aa.**').match('aa'), false);

expect(TagPattern('*').match('aa.bb'), false);
expect(TagPattern('*').match('aa'), true);
expect(TagPattern('*').match('bb'), true);

expect(TagPattern('**').match('aa.bb.cc'), true);
expect(TagPattern('**').match('aa.bb'), true);
expect(TagPattern('**').match('aa'), true);


  • Ignore FormatException


  • Simplyrfid paramater type
  • Update example


  • Update README.md


  • initial release.


example #

log collector example.

Use this package as a library

1. Depend on it

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

  log_collector: ^1.0.3

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:log_collector/log_collector.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 16, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health issues and suggestions

Document public APIs. (-0.60 points)

73 out of 74 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Maintenance suggestions

The package description is too short. (-15 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
path_provider ^1.2.0 1.5.1
synchronized ^2.1.0+1 2.1.1
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
platform 2.2.1
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies