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

View file

@ -6,4 +6,4 @@ import 'package:angel_framework/angel_framework.dart';
Future configureServer(Angel app) async {
// Include any plugins you have made here.
}
}

View file

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

View file

@ -16,7 +16,7 @@ AngelConfigurer configureServer(FileSystem fileSystem) {
return (Angel app) async {
// Enable CORS
app.use(cors());
// Typically, you want to mount controllers first, after any global middleware.
await app.configure(controllers.configureServer);

View file

@ -16,5 +16,5 @@ dependencies:
dev_dependencies:
angel_hot: ^1.1.0 # Hot-reloading support. :)
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