Crispin is heavily inspired by the fantastic WinstonJS project! Thus, the name of this project is a nod to the Winston project by way of another reference. In the video game Overwatch the character Winston is voiced by Crispin Freeman.

Don't comment out your logs (ever again). Use tests and configure loggers instead.


flutter pub add crispin

Basic Usage#

Crispin acts as a "Singleton" so you can configure it once and then use it throughout your application without ever needing comment out lines of code.

Setup transports

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

void main() {
  Crispin().addTransport(LoggerCrispinTransport(LoggerCrispinTransportOptions(level: dotenv.get('LOGGER_LEVEL', 'warn'))));
  // Note that an official SentryCrispinTransport is coming soon...
  // Crispin().addTransport(
  //  SentryCrispinTransport(
  //    SentryCrispinTransportOptions(
  //      level: dotenv.get('SENTRY_LEVEL', 'error'),
  //      //... keys
  //    ),
  //  ),
  // );

Now start logging

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);

A Powerful use case is zone guards

Future<void> runWithGuards() async {
  final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
    () async {
      await init(navigatorKey);

    (Object error, StackTrace stackTrace) async {
      Crispin().error('Zone Guard Caught Error', error: error, stackTrace: stackTrace);
      onUnhandledError(error, navigatorKey: navigatorKey, stackTrace: stackTrace); // <-- the navigatorKey is here for a nice trick when needing to perform navigation on errors.