2018-02-14 09:58:31 +00:00
|
|
|
import 'package:console/console.dart';
|
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
|
|
|
|
/// Prints the contents of a [LogRecord] with pretty colors.
|
2018-11-08 15:09:32 +00:00
|
|
|
prettyLog(LogRecord record) async {
|
2018-02-14 09:58:31 +00:00
|
|
|
var pen = new TextPen();
|
|
|
|
chooseLogColor(pen.reset(), record.level);
|
|
|
|
pen(record.toString());
|
2018-11-08 15:09:32 +00:00
|
|
|
|
|
|
|
if (record.error != null) pen(record.error.toString());
|
|
|
|
if (record.stackTrace != null) pen(record.stackTrace.toString());
|
|
|
|
|
2018-02-14 09:58:31 +00:00
|
|
|
pen();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Chooses a color based on the logger [level].
|
|
|
|
void chooseLogColor(TextPen pen, Level level) {
|
|
|
|
if (level == Level.SHOUT)
|
|
|
|
pen.darkRed();
|
|
|
|
else if (level == Level.SEVERE)
|
|
|
|
pen.red();
|
|
|
|
else if (level == Level.WARNING)
|
|
|
|
pen.yellow();
|
|
|
|
else if (level == Level.INFO)
|
|
|
|
pen.magenta();
|
|
|
|
else if (level == Level.FINER)
|
|
|
|
pen.blue();
|
2018-11-08 15:09:32 +00:00
|
|
|
else if (level == Level.FINEST) pen.darkBlue();
|
2018-02-14 09:58:31 +00:00
|
|
|
}
|