diff --git a/bin/dev.dart b/bin/dev.dart index fad7971..8a62248 100644 --- a/bin/dev.dart +++ b/bin/dev.dart @@ -1,23 +1,20 @@ 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'; -import 'package:logging/logging.dart'; +import 'package:lumberjack/lumberjack.dart'; +import 'package:lumberjack/io.dart'; main() async { // Watch the config/ and web/ directories for changes, and hot-reload the server. - var hot = new HotReloader(() async { - var app = new Angel(); + var hot = HotReloader(() async { + var app = Angel(); await app.configure(configureServer); - hierarchicalLoggingEnabled = true; - app.logger = new Logger('angel'); - var sub = app.logger.onRecord.listen(prettyLog); - app.shutdownHooks.add((_) => sub.cancel()); - return app; + app.logger = Logger('angel')..pipe(AnsiLogPrinter.toStdout()); + app.shutdownHooks.add((_) => app.logger.close()); }, [ - new Directory('config'), - new Directory('lib'), + Directory('config'), + Directory('lib'), ]); var server = await hot.startServer('127.0.0.1', 3000); diff --git a/bin/prod.dart b/bin/prod.dart index 01d40d0..2a9cf80 100644 --- a/bin/prod.dart +++ b/bin/prod.dart @@ -1,4 +1,4 @@ import 'package:angel/angel.dart'; import 'package:angel_production/angel_production.dart'; -main(List args) => new Runner('angel', configureServer).run(args); +main(List args) => Runner('angel', configureServer).run(args); diff --git a/lib/src/pretty_logging.dart b/lib/src/pretty_logging.dart deleted file mode 100644 index 3f8b452..0000000 --- a/lib/src/pretty_logging.dart +++ /dev/null @@ -1,35 +0,0 @@ -import 'package:angel_http_exception/angel_http_exception.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 code = chooseLogColor(record.level); - - 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; - print(code.wrap(record.toString() + '\n')); - print(code.wrap(err.toString())); - - if (record.stackTrace != null) { - print(code.wrap(record.stackTrace.toString())); - } - } -} - -/// Chooses a color based on the logger [level]. -AnsiCode chooseLogColor(Level level) { - if (level == Level.SHOUT) - return backgroundRed; - else if (level == Level.SEVERE) - return red; - else if (level == Level.WARNING) - return yellow; - else if (level == Level.INFO) - 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 bd6baf3..a75a12d 100644 --- a/lib/src/routes/routes.dart +++ b/lib/src/routes/routes.dart @@ -17,8 +17,7 @@ AngelConfigurer configureServer(FileSystem fileSystem) { await app.configure(controllers.configureServer); // Render `views/hello.jl` when a user visits the application root. - app.get( - '/', (RequestContext req, ResponseContext res) => res.render('hello')); + app.get('/', (req, res) => res.render('hello')); // Mount static server at web in development. // The `CachingVirtualDirectory` variant of `VirtualDirectory` also sends `Cache-Control` headers. @@ -30,7 +29,7 @@ AngelConfigurer configureServer(FileSystem fileSystem) { // * https://medium.com/the-angel-framework/serving-static-files-with-the-angel-framework-2ddc7a2b84ae // * https://github.com/angel-dart/static if (!app.isProduction) { - var vDir = new VirtualDirectory( + var vDir = VirtualDirectory( app, fileSystem, source: fileSystem.directory('web'), @@ -39,7 +38,7 @@ AngelConfigurer configureServer(FileSystem fileSystem) { } // Throw a 404 if no route matched the request. - app.fallback((req, res) => throw new AngelHttpException.notFound()); + app.fallback((req, res) => throw AngelHttpException.notFound()); // Set our application up to handle different errors. // diff --git a/test/all_test.dart b/test/all_test.dart index c4cb235..f059daf 100644 --- a/test/all_test.dart +++ b/test/all_test.dart @@ -23,7 +23,7 @@ main() async { TestClient client; setUp(() async { - var app = new Angel(); + var app = Angel(); await app.configure(configureServer); client = await connectTo(app);