From ac9d66f036f521ab80a61c7537dc3bb2c1ab6e86 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sun, 15 Jul 2018 00:31:40 -0400 Subject: [PATCH] Use package:io for colors --- bin/prod.dart | 5 ++--- lib/src/config/plugins/plugins.dart | 2 +- lib/src/pretty_logging.dart | 33 ++++++++++++++--------------- lib/src/routes/routes.dart | 2 +- pubspec.yaml | 2 +- 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/bin/prod.dart b/bin/prod.dart index 584c581..d805b24 100644 --- a/bin/prod.dart +++ b/bin/prod.dart @@ -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}'); }); } diff --git a/lib/src/config/plugins/plugins.dart b/lib/src/config/plugins/plugins.dart index 5d9673d..b025b21 100644 --- a/lib/src/config/plugins/plugins.dart +++ b/lib/src/config/plugins/plugins.dart @@ -6,4 +6,4 @@ import 'package:angel_framework/angel_framework.dart'; Future configureServer(Angel app) async { // Include any plugins you have made here. -} \ No newline at end of file +} diff --git a/lib/src/pretty_logging.dart b/lib/src/pretty_logging.dart index 625ca12..3f8b452 100644 --- a/lib/src/pretty_logging.dart +++ b/lib/src/pretty_logging.dart @@ -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; } diff --git a/lib/src/routes/routes.dart b/lib/src/routes/routes.dart index 44855b2..a01e550 100644 --- a/lib/src/routes/routes.dart +++ b/lib/src/routes/routes.dart @@ -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); diff --git a/pubspec.yaml b/pubspec.yaml index 406f2a2..d18a39f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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