This commit is contained in:
Tobe O 2017-10-20 02:22:34 -04:00
parent 84c67e7094
commit 0ce75194b1
2 changed files with 35 additions and 7 deletions

View file

@ -1,4 +1,5 @@
import 'dart:io';
import 'package:angel/src/pretty_logging.dart';
import 'package:angel/angel.dart';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_hot/angel_hot.dart';
@ -9,13 +10,8 @@ main() async {
var hot = new HotReloader(() async {
var app = new Angel()..lazyParseBodies = true;
await app.configure(configureServer);
app.logger = new Logger('angel')..onRecord.listen((rec) {
print(rec);
if (rec.error != null) {
print(rec.error);
print(rec.stackTrace);
}
});
app.logger = new Logger('angel')
..onRecord.listen(prettyLog);
return app;
}, [
new Directory('config'),

View file

@ -0,0 +1,32 @@
import 'package:console/console.dart';
import 'package:logging/logging.dart';
/// Prints the contents of a [LogRecord] with pretty colors.
void prettyLog(LogRecord record) async {
var pen = new TextPen();
chooseLogColor(pen.reset(), record.level);
pen(record.toString());
if (record.error != null)
pen.record.error.toString();
if (record.stackTrace != null)
pen.record.stackTrace.toString();
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();
}