Colorful logging for Flutter

logging_colorful

I’m using the logging package and i wanted it to be colorful. When I searched for this, I found packages with way too much features and dependencies.

So I created this package with no other dependencies than the necessary logging.

If you don’t want to import this package, you can take the two files in lib/src.

Features

  • Colorful logging
  • Change color for each Level

Usage

import 'package:logging_colorful/logging_colorful.dart';

void main() {
  // Define your Logger configuration
  Logger.root.level = Level.ALL;
  Logger.root.onRecord.listen((record) {
    print('${record.loggerName} - ${record.level.name}: ${record.message}');
  });

// Initialize a LoggerColorful that will make your logger colorized
  final log = LoggerColorful('MyLogger');
  log.shout('shout');
  log.severe('severe');
  log.warning('warning');
  log.info('info');
  log.config('config');
  log.fine('fine');
  log.finer('finer');
  log.finest('finest');

  // Change the Color for a Level
  // (In this case we assign an AnsiColor to [Level.FINEST] which has no AnsiColor to remove the rainbow)
  log.colorLevel[Level.FINEST] = AnsiColor.backgroundGreen;
  log.finest('finest with color instead of rainbow');
}

Screenshots

1.0.0

Additional information

All the available colors are listed in lib/src/color.dart file.

GitHub

View Github

Description of the image

Related Posts