Use package:io for colors

This commit is contained in:
Tobe O 2018-07-15 00:31:40 -04:00
parent 40fcfe9ab2
commit ac9d66f036
5 changed files with 21 additions and 23 deletions

View file

@ -2,7 +2,6 @@ import 'dart:io';
import 'dart:isolate'; import 'dart:isolate';
import 'package:angel/angel.dart'; import 'package:angel/angel.dart';
import 'package:angel_framework/angel_framework.dart'; import 'package:angel_framework/angel_framework.dart';
import 'package:dart2_constant/io.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
const String hostname = '127.0.0.1'; const String hostname = '127.0.0.1';
@ -42,7 +41,7 @@ void isolateMain(int id) {
// This effectively lets us multi-thread the application. // This effectively lets us multi-thread the application.
var http = new AngelHttp.custom(app, startShared); var http = new AngelHttp.custom(app, startShared);
var server = await http.startServer(hostname, port); var server = await http.startServer(hostname, port);
print('Instance #$id listening at http://${server.address.address}:${server print(
.port}'); 'Instance #$id listening at http://${server.address.address}:${server.port}');
}); });
} }

View file

@ -1,36 +1,35 @@
import 'package:angel_http_exception/angel_http_exception.dart'; import 'package:angel_http_exception/angel_http_exception.dart';
import 'package:console/console.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:io/ansi.dart';
/// Prints the contents of a [LogRecord] with pretty colors. /// Prints the contents of a [LogRecord] with pretty colors.
void prettyLog(LogRecord record) { void prettyLog(LogRecord record) {
var pen = new TextPen(); var code = chooseLogColor(record.level);
chooseLogColor(pen.reset(), record.level);
if (record.error == null) pen(record.toString()); if (record.error == null) print(code.wrap(record.toString()));
if (record.error != null) { if (record.error != null) {
var err = record.error; var err = record.error;
if (err is AngelHttpException && err.statusCode != 500) return; if (err is AngelHttpException && err.statusCode != 500) return;
pen(record.toString() + '\n'); print(code.wrap(record.toString() + '\n'));
pen(err.toString()); print(code.wrap(err.toString()));
if (record.stackTrace != null) pen(record.stackTrace.toString());
}
pen(); if (record.stackTrace != null) {
print(code.wrap(record.stackTrace.toString()));
}
}
} }
/// Chooses a color based on the logger [level]. /// Chooses a color based on the logger [level].
void chooseLogColor(TextPen pen, Level level) { AnsiCode chooseLogColor(Level level) {
if (level == Level.SHOUT) if (level == Level.SHOUT)
pen.darkRed(); return backgroundRed;
else if (level == Level.SEVERE) else if (level == Level.SEVERE)
pen.red(); return red;
else if (level == Level.WARNING) else if (level == Level.WARNING)
pen.yellow(); return yellow;
else if (level == Level.INFO) else if (level == Level.INFO)
pen.magenta(); return cyan;
else if (level == Level.FINER) else if (level == Level.FINER || level == Level.FINEST) return lightGray;
pen.blue(); return resetAll;
else if (level == Level.FINEST) pen.darkBlue();
} }

View file

@ -16,5 +16,5 @@ dependencies:
dev_dependencies: dev_dependencies:
angel_hot: ^1.1.0 # Hot-reloading support. :) angel_hot: ^1.1.0 # Hot-reloading support. :)
angel_test: ^1.1.0 # Utilities for testing Angel servers. angel_test: ^1.1.0 # Utilities for testing Angel servers.
console: ">=2.0.0 <4.0.0" io: ^0.3.2
test: ^0.12.13 test: ^0.12.13