From 803f446a012e07bf7fe6303272a9c165151fb92c Mon Sep 17 00:00:00 2001 From: Tobe O Date: Mon, 10 Dec 2018 22:19:16 -0500 Subject: [PATCH] 2.0.0-alpha.16 --- CHANGELOG.md | 3 +++ example/http2/body_parsing.dart | 6 +++--- example/http2/main.dart | 6 +++--- example/http2/server_push.dart | 6 +++--- example/main.dart | 11 +++-------- lib/src/core/driver.dart | 16 +++++++++------- lib/src/core/server.dart | 24 ++++++++++++++++++++---- lib/src/http2/angel_http2.dart | 4 ++-- pubspec.yaml | 3 ++- test/services_test.dart | 2 +- 10 files changed, 49 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ed1eeb8..c43c242c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 2.0.0-alpha.16 +* Use `package:lumberjack` for logging. + # 2.0.0-alpha.15 * Remove dependency on `body_parser`. * `RequestContext` now exposes a `Stream> get body` getter. diff --git a/example/http2/body_parsing.dart b/example/http2/body_parsing.dart index 93c4a78d..ffc3e57a 100644 --- a/example/http2/body_parsing.dart +++ b/example/http2/body_parsing.dart @@ -25,10 +25,10 @@ main() async { try { ctx.setAlpnProtocols(['h2'], true); } catch (e, st) { - app.logger.severe( + app.logger.error( 'Cannot set ALPN protocol on server to `h2`. The server will only serve HTTP/1.x.', - e, - st, + error: e, + stackTrace: st, ); } diff --git a/example/http2/main.dart b/example/http2/main.dart index e381c48c..0f4ebf38 100644 --- a/example/http2/main.dart +++ b/example/http2/main.dart @@ -25,10 +25,10 @@ main() async { try { ctx.setAlpnProtocols(['h2'], true); } catch (e, st) { - app.logger.severe( + app.logger.error( 'Cannot set ALPN protocol on server to `h2`. The server will only serve HTTP/1.x.', - e, - st, + error: e, + stackTrace: st, ); } diff --git a/example/http2/server_push.dart b/example/http2/server_push.dart index 439b7fb9..3ebec6c5 100644 --- a/example/http2/server_push.dart +++ b/example/http2/server_push.dart @@ -41,10 +41,10 @@ main() async { try { ctx.setAlpnProtocols(['h2'], true); } catch (e, st) { - app.logger.severe( + app.logger.error( 'Cannot set ALPN protocol on server to `h2`. The server will only serve HTTP/1.x.', - e, - st, + error: e, + stackTrace: st, ); } diff --git a/example/main.dart b/example/main.dart index 6d0934eb..c671de60 100644 --- a/example/main.dart +++ b/example/main.dart @@ -1,7 +1,8 @@ import 'package:angel_container/mirrors.dart'; import 'package:angel_framework/angel_framework.dart'; import 'package:angel_framework/http.dart'; -import 'package:logging/logging.dart'; +import 'package:lumberjack/lumberjack.dart'; +import 'package:lumberjack/io.dart'; main() async { var app = new Angel( @@ -9,13 +10,7 @@ main() async { reflector: MirrorsReflector(), ); - hierarchicalLoggingEnabled = true; - - app.logger.onRecord.listen((rec) { - print(rec); - if (rec.error != null) print(rec.error); - if (rec.stackTrace != null) print(rec.stackTrace); - }); + app.logger.pipe(AnsiLogPrinter.toStdout()); // Index route. Returns JSON. app.get('/', (req, res) => 'Welcome to Angel!'); diff --git a/lib/src/core/driver.dart b/lib/src/core/driver.dart index 1bb9d50b..ae556e06 100644 --- a/lib/src/core/driver.dart +++ b/lib/src/core/driver.dart @@ -167,7 +167,8 @@ abstract class Driver< var error = e.error ?? e; var trace = new Trace.from(e.stackTrace ?? StackTrace.current).terse; - app.logger.severe(e.message ?? e.toString(), error, trace); + app.logger.error(e.message ?? e.toString(), + error: error, stackTrace: trace); } return handleAngelHttpException( @@ -177,7 +178,7 @@ abstract class Driver< var zoneSpec = new ZoneSpecification( print: (self, parent, zone, line) { if (app.logger != null) - app.logger.info(line); + app.logger.information(line); else parent.print(zone, line); }, @@ -200,7 +201,8 @@ abstract class Driver< } if (app.logger != null) { - app.logger.severe(e.message ?? e.toString(), error, trace); + app.logger.error(e.message ?? e.toString(), + error: error, stackTrace: trace); } return handleAngelHttpException( @@ -211,8 +213,8 @@ abstract class Driver< // Ideally, we won't be in a position where an absolutely fatal error occurs, // but if so, we'll need to log it. if (app.logger != null) { - app.logger.severe( - 'Fatal error occurred when processing $uri.', e, trace); + app.logger.error('Fatal error occurred when processing $uri.', + error: e, stackTrace: trace); } else { stderr ..writeln('Fatal error occurred when processing ' @@ -253,7 +255,7 @@ abstract class Driver< {bool ignoreFinalizers: false}) { if (req == null || res == null) { try { - app.logger?.severe(e, st); + app.logger?.error(null, error: e, stackTrace: st); setStatusCode(response, 500); writeStringToResponse(response, '500 Internal Server Error'); closeResponse(response); @@ -285,7 +287,7 @@ abstract class Driver< void _cleanup(_) { if (!app.isProduction && app.logger != null) { var sw = req.container.make(); - app.logger.info( + app.logger.information( "${res.statusCode} ${req.method} ${req.uri} (${sw?.elapsedMilliseconds ?? 'unknown'} ms)"); } } diff --git a/lib/src/core/server.dart b/lib/src/core/server.dart index a86fc84d..c024ef5b 100644 --- a/lib/src/core/server.dart +++ b/lib/src/core/server.dart @@ -10,7 +10,9 @@ import 'package:angel_http_exception/angel_http_exception.dart'; import 'package:angel_route/angel_route.dart'; import 'package:combinator/combinator.dart'; import 'package:http_parser/http_parser.dart'; -import 'package:logging/logging.dart'; +import 'package:logging/logging.dart' as dart; +import 'package:lumberjack/logging.dart'; +import 'package:lumberjack/lumberjack.dart'; import 'package:mime/mime.dart'; import 'package:tuple/tuple.dart'; @@ -90,7 +92,20 @@ class Angel extends Routable { Angel get parent => _parent; /// Outputs diagnostics and debug messages. - Logger logger; + Logger get logger => _logger; + + set logger(value) { + if (_logger != null) _logger.close(); + if (value is dart.Logger) { + _logger = new ConvertingLogger(value); + } else if (value is Logger) { + _logger = value; + } else { + throw new ArgumentError(); + } + } + + Logger _logger; /// Plug-ins to be called right before server startup. /// @@ -292,7 +307,7 @@ class Angel extends Routable { if (isProduction == true || force == true) { _isProduction = true; _flattened ??= flatten(this); - logger?.config('Angel is running in production mode.'); + logger?.notice('Angel is running in production mode.'); } } @@ -352,11 +367,12 @@ class Angel extends Routable { Angel( {Reflector reflector: const EmptyReflector(), - this.logger, + logger, this.allowMethodOverrides: true, this.serializer, this.viewGenerator}) : super(reflector) { + if (logger != null) this.logger = logger; bootstrapContainer(); viewGenerator ??= noViewEngineConfigured; serializer ??= json.encode; diff --git a/lib/src/http2/angel_http2.dart b/lib/src/http2/angel_http2.dart index 3a90e58f..a041e5f5 100644 --- a/lib/src/http2/angel_http2.dart +++ b/lib/src/http2/angel_http2.dart @@ -191,8 +191,8 @@ class _AngelHttp2ServerSocket extends Stream }, onDone: _ctrl.close, onError: (e, st) { - driver.app.logger.warning( - 'HTTP/2 incoming connection failure: ', e, st as StackTrace); + driver.app.logger.warning('HTTP/2 incoming connection failure: ', + error: e, stackTrace: st as StackTrace); }, ); } diff --git a/pubspec.yaml b/pubspec.yaml index 245e192e..b091d332 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_framework -version: 2.0.0-alpha.15 +version: 2.0.0-alpha.16 description: A high-powered HTTP server with dependency injection, routing and much more. author: Tobe O homepage: https://github.com/angel-dart/angel_framework @@ -17,6 +17,7 @@ dependencies: http_server: ^0.9.0 http2: ">=0.1.7 <2.0.0" logging: ">=0.11.3 <1.0.0" + lumberjack: ^1.0.0-rc.0 matcher: ^0.12.0 merge_map: ^1.0.0 meta: ^1.0.0 diff --git a/test/services_test.dart b/test/services_test.dart index 2afcb38d..8b881be3 100644 --- a/test/services_test.dart +++ b/test/services_test.dart @@ -77,7 +77,7 @@ main() { await client.post("$url/todos", headers: headers as Map, body: postData); postData = json.encode({'text': 'modified'}); - + var response = await client.patch("$url/todos/0", headers: headers as Map, body: postData); expect(response.statusCode, 200);