DEV Community

John Bailey
John Bailey

Posted on • Edited on

Crispin: Logger Facade for Flutter

Introducing Crispin!

From Sentry to Splunk to console logging, controlling all of these log targets can quickly get complicated and distracting from our feature code.

While several languages have Logging facades, Flutter and Dart were lacking. As such, @gillarohith and I created one for Flutter and Dart that is heavily inspired by WinstonJS. We call it Crispin

While you can read more examples and details in our documentation, below is some quick start usage and setup.

Basic Usage

void getUser () async {
  try {
    User user = await DataService.getUserById('1');
    Crispin().info('User data', meta: user);
  } catch(e, s) {
    Crispin().error('User fetching failed', error: e, stackTrace: s);
  }
}
Enter fullscreen mode Exit fullscreen mode

Setup

import 'package:crispin/crispin.dart';
import 'package:logger_crispin_transport/logger_crispin_transport.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:sentry_crispin_transport/src/sentry_crispin_transport.dart';

void main() {
  Crispin().addTransport(
    LoggerCrispinTransport(
       LoggerCrispinTransportOptions(
          level: dotenv.get('LOGGER_LEVEL', 'warn'),
       ),
    ),
  );
  Crispin().addTransport(
    SentryCrispinTransport(
      SentryCrispinTransportOptions(
        level: dotenv.get('SENTRY_LEVEL', 'error'),
        //... keys
      ),
    ),
  );
}
Enter fullscreen mode Exit fullscreen mode

Next Steps

I have channels planned but welcome contributions and other loggers (log targets)!

Top comments (0)