2018-01-08 21:04:52 +00:00
|
|
|
import 'package:console/console.dart';
|
|
|
|
import 'package:logging/logging.dart';
|
2018-01-09 14:44:59 +00:00
|
|
|
import 'package:stack_trace/stack_trace.dart';
|
2018-01-08 21:04:52 +00:00
|
|
|
|
|
|
|
/// Prints the contents of a [LogRecord] with pretty colors.
|
|
|
|
void prettyLog(LogRecord record) {
|
|
|
|
var pen = new TextPen();
|
|
|
|
chooseLogColor(pen.reset(), record.level);
|
|
|
|
pen(record.toString());
|
|
|
|
|
|
|
|
if (record.error != null)
|
|
|
|
pen(record.error.toString());
|
|
|
|
if (record.stackTrace != null)
|
2018-01-09 14:44:59 +00:00
|
|
|
pen(new Chain.forTrace(record.stackTrace).terse.toString());
|
2018-01-08 21:04:52 +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();
|
|
|
|
else if (level == Level.FINEST)
|
|
|
|
pen.darkBlue();
|
|
|
|
}
|