17
This commit is contained in:
parent
5af191eebb
commit
1f83c4acb2
12 changed files with 71 additions and 68 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
# 2.0.0-alpha.17
|
||||||
|
* Revert the migration to `lumberjack` for now. In the future, when it's more
|
||||||
|
stable, there'll be a conversion, perhaps.
|
||||||
|
|
||||||
# 2.0.0-alpha.16
|
# 2.0.0-alpha.16
|
||||||
* Use `package:lumberjack` for logging.
|
* Use `package:lumberjack` for logging.
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,16 @@ import 'dart:io';
|
||||||
import 'package:angel_container/mirrors.dart';
|
import 'package:angel_container/mirrors.dart';
|
||||||
import 'package:angel_framework/angel_framework.dart';
|
import 'package:angel_framework/angel_framework.dart';
|
||||||
import 'package:angel_framework/http.dart';
|
import 'package:angel_framework/http.dart';
|
||||||
import 'package:lumberjack/lumberjack.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:lumberjack/io.dart';
|
|
||||||
|
|
||||||
main() async {
|
main() async {
|
||||||
var app = new Angel(reflector: MirrorsReflector())
|
var app = new Angel(reflector: MirrorsReflector())
|
||||||
..logger = (new Logger('angel')..pipe(new AnsiLogPrinter.toStdout()))
|
..logger = (new Logger('angel')
|
||||||
|
..onRecord.listen((rec) {
|
||||||
|
print(rec);
|
||||||
|
if (rec.error != null) print(rec.error);
|
||||||
|
if (rec.stackTrace != null) print(rec.stackTrace);
|
||||||
|
}))
|
||||||
..encoders.addAll({'gzip': gzip.encoder});
|
..encoders.addAll({'gzip': gzip.encoder});
|
||||||
|
|
||||||
app.fallback(
|
app.fallback(
|
||||||
|
|
|
@ -3,13 +3,16 @@ import 'package:angel_framework/angel_framework.dart';
|
||||||
import 'package:angel_framework/http.dart';
|
import 'package:angel_framework/http.dart';
|
||||||
import 'package:angel_framework/http2.dart';
|
import 'package:angel_framework/http2.dart';
|
||||||
import 'package:file/local.dart';
|
import 'package:file/local.dart';
|
||||||
import 'package:lumberjack/lumberjack.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:lumberjack/io.dart';
|
|
||||||
|
|
||||||
main() async {
|
main() async {
|
||||||
var app = new Angel();
|
var app = new Angel();
|
||||||
app.logger = new Logger('angel');
|
app.logger = new Logger('angel')
|
||||||
app.logger.pipe(new AnsiLogPrinter.toStdout());
|
..onRecord.listen((rec) {
|
||||||
|
print(rec);
|
||||||
|
if (rec.error != null) print(rec.error);
|
||||||
|
if (rec.stackTrace != null) print(rec.stackTrace);
|
||||||
|
});
|
||||||
|
|
||||||
var publicDir = new Directory('example/public');
|
var publicDir = new Directory('example/public');
|
||||||
var indexHtml =
|
var indexHtml =
|
||||||
|
@ -26,11 +29,10 @@ main() async {
|
||||||
try {
|
try {
|
||||||
ctx.setAlpnProtocols(['h2'], true);
|
ctx.setAlpnProtocols(['h2'], true);
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
app.logger.error(
|
app.logger.severe(
|
||||||
'Cannot set ALPN protocol on server to `h2`. The server will only serve HTTP/1.x.',
|
'Cannot set ALPN protocol on server to `h2`. The server will only serve HTTP/1.x.',
|
||||||
error: e,
|
e,
|
||||||
stackTrace: st,
|
st);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var http1 = new AngelHttp(app);
|
var http1 = new AngelHttp(app);
|
||||||
|
|
7
example/http2/common.dart
Normal file
7
example/http2/common.dart
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import 'package:logging/logging.dart';
|
||||||
|
|
||||||
|
void dumpError(LogRecord rec) {
|
||||||
|
print(rec);
|
||||||
|
if (rec.error != null) print(rec.error);
|
||||||
|
if (rec.stackTrace != null) print(rec.stackTrace);
|
||||||
|
}
|
|
@ -2,8 +2,8 @@ import 'dart:io';
|
||||||
import 'package:angel_framework/angel_framework.dart';
|
import 'package:angel_framework/angel_framework.dart';
|
||||||
import 'package:angel_framework/http.dart';
|
import 'package:angel_framework/http.dart';
|
||||||
import 'package:angel_framework/http2.dart';
|
import 'package:angel_framework/http2.dart';
|
||||||
import 'package:lumberjack/lumberjack.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:lumberjack/io.dart';
|
import 'common.dart';
|
||||||
|
|
||||||
main() async {
|
main() async {
|
||||||
var app = new Angel()
|
var app = new Angel()
|
||||||
|
@ -11,8 +11,7 @@ main() async {
|
||||||
'gzip': gzip.encoder,
|
'gzip': gzip.encoder,
|
||||||
'deflate': zlib.encoder,
|
'deflate': zlib.encoder,
|
||||||
});
|
});
|
||||||
app.logger = new Logger('angel');
|
app.logger = new Logger('angel')..onRecord.listen(dumpError);
|
||||||
app.logger.pipe(new AnsiLogPrinter.toStdout());
|
|
||||||
|
|
||||||
app.get('/', (req, res) => 'Hello HTTP/2!!!');
|
app.get('/', (req, res) => 'Hello HTTP/2!!!');
|
||||||
|
|
||||||
|
@ -26,10 +25,10 @@ main() async {
|
||||||
try {
|
try {
|
||||||
ctx.setAlpnProtocols(['h2'], true);
|
ctx.setAlpnProtocols(['h2'], true);
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
app.logger.error(
|
app.logger.severe(
|
||||||
'Cannot set ALPN protocol on server to `h2`. The server will only serve HTTP/1.x.',
|
'Cannot set ALPN protocol on server to `h2`. The server will only serve HTTP/1.x.',
|
||||||
error: e,
|
e,
|
||||||
stackTrace: st,
|
st,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,16 @@ import 'package:angel_framework/angel_framework.dart';
|
||||||
import 'package:angel_framework/http.dart';
|
import 'package:angel_framework/http.dart';
|
||||||
import 'package:angel_framework/http2.dart';
|
import 'package:angel_framework/http2.dart';
|
||||||
import 'package:file/local.dart';
|
import 'package:file/local.dart';
|
||||||
import 'package:lumberjack/lumberjack.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:lumberjack/io.dart';
|
|
||||||
|
|
||||||
main() async {
|
main() async {
|
||||||
var app = new Angel();
|
var app = new Angel();
|
||||||
app.logger = new Logger('angel');
|
app.logger = new Logger('angel')
|
||||||
app.logger.pipe(new AnsiLogPrinter.toStdout());
|
..onRecord.listen((rec) {
|
||||||
|
print(rec);
|
||||||
|
if (rec.error != null) print(rec.error);
|
||||||
|
if (rec.stackTrace != null) print(rec.stackTrace);
|
||||||
|
});
|
||||||
|
|
||||||
var publicDir = new Directory('example/http2/public');
|
var publicDir = new Directory('example/http2/public');
|
||||||
var indexHtml =
|
var indexHtml =
|
||||||
|
@ -42,11 +45,10 @@ main() async {
|
||||||
try {
|
try {
|
||||||
ctx.setAlpnProtocols(['h2'], true);
|
ctx.setAlpnProtocols(['h2'], true);
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
app.logger.error(
|
app.logger.severe(
|
||||||
'Cannot set ALPN protocol on server to `h2`. The server will only serve HTTP/1.x.',
|
'Cannot set ALPN protocol on server to `h2`. The server will only serve HTTP/1.x.',
|
||||||
error: e,
|
e,
|
||||||
stackTrace: st,
|
st);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var http1 = new AngelHttp(app);
|
var http1 = new AngelHttp(app);
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import 'package:angel_container/mirrors.dart';
|
import 'package:angel_container/mirrors.dart';
|
||||||
import 'package:angel_framework/angel_framework.dart';
|
import 'package:angel_framework/angel_framework.dart';
|
||||||
import 'package:angel_framework/http.dart';
|
import 'package:angel_framework/http.dart';
|
||||||
import 'package:lumberjack/lumberjack.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:lumberjack/io.dart';
|
|
||||||
|
|
||||||
main() async {
|
main() async {
|
||||||
var app = new Angel(
|
var app = new Angel(
|
||||||
|
@ -10,7 +9,12 @@ main() async {
|
||||||
reflector: MirrorsReflector(),
|
reflector: MirrorsReflector(),
|
||||||
);
|
);
|
||||||
|
|
||||||
app.logger.pipe(AnsiLogPrinter.toStdout());
|
app.logger = new Logger('angel')
|
||||||
|
..onRecord.listen((rec) {
|
||||||
|
print(rec);
|
||||||
|
if (rec.error != null) print(rec.error);
|
||||||
|
if (rec.stackTrace != null) print(rec.stackTrace);
|
||||||
|
});
|
||||||
|
|
||||||
// Index route. Returns JSON.
|
// Index route. Returns JSON.
|
||||||
app.get('/', (req, res) => 'Welcome to Angel!');
|
app.get('/', (req, res) => 'Welcome to Angel!');
|
||||||
|
|
|
@ -167,8 +167,7 @@ abstract class Driver<
|
||||||
var error = e.error ?? e;
|
var error = e.error ?? e;
|
||||||
var trace =
|
var trace =
|
||||||
new Trace.from(e.stackTrace ?? StackTrace.current).terse;
|
new Trace.from(e.stackTrace ?? StackTrace.current).terse;
|
||||||
app.logger.error(e.message ?? e.toString(),
|
app.logger.severe(e.message ?? e.toString(), error, trace);
|
||||||
error: error, stackTrace: trace);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return handleAngelHttpException(
|
return handleAngelHttpException(
|
||||||
|
@ -178,7 +177,7 @@ abstract class Driver<
|
||||||
var zoneSpec = new ZoneSpecification(
|
var zoneSpec = new ZoneSpecification(
|
||||||
print: (self, parent, zone, line) {
|
print: (self, parent, zone, line) {
|
||||||
if (app.logger != null)
|
if (app.logger != null)
|
||||||
app.logger.information(line);
|
app.logger.info(line);
|
||||||
else
|
else
|
||||||
parent.print(zone, line);
|
parent.print(zone, line);
|
||||||
},
|
},
|
||||||
|
@ -201,8 +200,7 @@ abstract class Driver<
|
||||||
}
|
}
|
||||||
|
|
||||||
if (app.logger != null) {
|
if (app.logger != null) {
|
||||||
app.logger.error(e.message ?? e.toString(),
|
app.logger.severe(e.message ?? e.toString(), error, trace);
|
||||||
error: error, stackTrace: trace);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return handleAngelHttpException(
|
return handleAngelHttpException(
|
||||||
|
@ -213,8 +211,8 @@ abstract class Driver<
|
||||||
// Ideally, we won't be in a position where an absolutely fatal error occurs,
|
// Ideally, we won't be in a position where an absolutely fatal error occurs,
|
||||||
// but if so, we'll need to log it.
|
// but if so, we'll need to log it.
|
||||||
if (app.logger != null) {
|
if (app.logger != null) {
|
||||||
app.logger.error('Fatal error occurred when processing $uri.',
|
app.logger.severe(
|
||||||
error: e, stackTrace: trace);
|
'Fatal error occurred when processing $uri.', e, trace);
|
||||||
} else {
|
} else {
|
||||||
stderr
|
stderr
|
||||||
..writeln('Fatal error occurred when processing '
|
..writeln('Fatal error occurred when processing '
|
||||||
|
@ -255,7 +253,7 @@ abstract class Driver<
|
||||||
{bool ignoreFinalizers: false}) {
|
{bool ignoreFinalizers: false}) {
|
||||||
if (req == null || res == null) {
|
if (req == null || res == null) {
|
||||||
try {
|
try {
|
||||||
app.logger?.error(null, error: e, stackTrace: st);
|
app.logger?.severe(null, e, st);
|
||||||
setStatusCode(response, 500);
|
setStatusCode(response, 500);
|
||||||
writeStringToResponse(response, '500 Internal Server Error');
|
writeStringToResponse(response, '500 Internal Server Error');
|
||||||
closeResponse(response);
|
closeResponse(response);
|
||||||
|
@ -287,7 +285,7 @@ abstract class Driver<
|
||||||
void _cleanup(_) {
|
void _cleanup(_) {
|
||||||
if (!app.isProduction && app.logger != null) {
|
if (!app.isProduction && app.logger != null) {
|
||||||
var sw = req.container.make<Stopwatch>();
|
var sw = req.container.make<Stopwatch>();
|
||||||
app.logger.information(
|
app.logger.info(
|
||||||
"${res.statusCode} ${req.method} ${req.uri} (${sw?.elapsedMilliseconds ?? 'unknown'} ms)");
|
"${res.statusCode} ${req.method} ${req.uri} (${sw?.elapsedMilliseconds ?? 'unknown'} ms)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,7 @@ import 'package:angel_http_exception/angel_http_exception.dart';
|
||||||
import 'package:angel_route/angel_route.dart';
|
import 'package:angel_route/angel_route.dart';
|
||||||
import 'package:combinator/combinator.dart';
|
import 'package:combinator/combinator.dart';
|
||||||
import 'package:http_parser/http_parser.dart';
|
import 'package:http_parser/http_parser.dart';
|
||||||
import 'package:logging/logging.dart' as dart;
|
import 'package:logging/logging.dart';
|
||||||
import 'package:lumberjack/logging.dart';
|
|
||||||
import 'package:lumberjack/lumberjack.dart';
|
|
||||||
import 'package:mime/mime.dart';
|
import 'package:mime/mime.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
import 'package:tuple/tuple.dart';
|
||||||
|
|
||||||
|
@ -92,20 +90,7 @@ class Angel extends Routable {
|
||||||
Angel get parent => _parent;
|
Angel get parent => _parent;
|
||||||
|
|
||||||
/// Outputs diagnostics and debug messages.
|
/// Outputs diagnostics and debug messages.
|
||||||
Logger get logger => _logger;
|
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 if (value != null) {
|
|
||||||
throw new ArgumentError('Unsupported logger: $value');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger _logger;
|
|
||||||
|
|
||||||
/// Plug-ins to be called right before server startup.
|
/// Plug-ins to be called right before server startup.
|
||||||
///
|
///
|
||||||
|
@ -307,7 +292,7 @@ class Angel extends Routable {
|
||||||
if (isProduction == true || force == true) {
|
if (isProduction == true || force == true) {
|
||||||
_isProduction = true;
|
_isProduction = true;
|
||||||
_flattened ??= flatten(this);
|
_flattened ??= flatten(this);
|
||||||
logger?.notice('Angel is running in production mode.');
|
logger?.info('Angel is running in production mode.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,12 +352,11 @@ class Angel extends Routable {
|
||||||
|
|
||||||
Angel(
|
Angel(
|
||||||
{Reflector reflector: const EmptyReflector(),
|
{Reflector reflector: const EmptyReflector(),
|
||||||
logger,
|
this.logger,
|
||||||
this.allowMethodOverrides: true,
|
this.allowMethodOverrides: true,
|
||||||
this.serializer,
|
this.serializer,
|
||||||
this.viewGenerator})
|
this.viewGenerator})
|
||||||
: super(reflector) {
|
: super(reflector) {
|
||||||
if (logger != null) this.logger = logger;
|
|
||||||
bootstrapContainer();
|
bootstrapContainer();
|
||||||
viewGenerator ??= noViewEngineConfigured;
|
viewGenerator ??= noViewEngineConfigured;
|
||||||
serializer ??= json.encode;
|
serializer ??= json.encode;
|
||||||
|
|
|
@ -191,8 +191,8 @@ class _AngelHttp2ServerSocket extends Stream<SecureSocket>
|
||||||
},
|
},
|
||||||
onDone: _ctrl.close,
|
onDone: _ctrl.close,
|
||||||
onError: (e, st) {
|
onError: (e, st) {
|
||||||
driver.app.logger.warning('HTTP/2 incoming connection failure: ',
|
driver.app.logger.warning(
|
||||||
error: e, stackTrace: st as StackTrace);
|
'HTTP/2 incoming connection failure: ', e, st as StackTrace);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Http2RequestContext extends RequestContext<ServerTransportStream> {
|
||||||
Socket socket,
|
Socket socket,
|
||||||
Angel app,
|
Angel app,
|
||||||
Map<String, MockHttpSession> sessions,
|
Map<String, MockHttpSession> sessions,
|
||||||
Uuid uuid) async {
|
Uuid uuid) {
|
||||||
var c = new Completer<Http2RequestContext>();
|
var c = new Completer<Http2RequestContext>();
|
||||||
var req = new Http2RequestContext._(app.container.createChild())
|
var req = new Http2RequestContext._(app.container.createChild())
|
||||||
..app = app
|
..app = app
|
||||||
|
@ -63,7 +63,7 @@ class Http2RequestContext extends RequestContext<ServerTransportStream> {
|
||||||
|
|
||||||
stream.incomingMessages.listen((msg) {
|
stream.incomingMessages.listen((msg) {
|
||||||
if (msg is DataStreamMessage) {
|
if (msg is DataStreamMessage) {
|
||||||
if (!c.isCompleted) finalize();
|
finalize();
|
||||||
req._body.add(msg.bytes);
|
req._body.add(msg.bytes);
|
||||||
} else if (msg is HeadersStreamMessage) {
|
} else if (msg is HeadersStreamMessage) {
|
||||||
for (var header in msg.headers) {
|
for (var header in msg.headers) {
|
||||||
|
@ -108,10 +108,10 @@ class Http2RequestContext extends RequestContext<ServerTransportStream> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.endStream && !c.isCompleted) finalize();
|
if (msg.endStream) finalize();
|
||||||
}
|
}
|
||||||
}, onDone: () {
|
}, onDone: () {
|
||||||
if (!c.isCompleted) finalize();
|
finalize();
|
||||||
}, cancelOnError: true, onError: c.completeError);
|
}, cancelOnError: true, onError: c.completeError);
|
||||||
|
|
||||||
// Apply session
|
// Apply session
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: angel_framework
|
name: angel_framework
|
||||||
version: 2.0.0-alpha.16
|
version: 2.0.0-alpha.17
|
||||||
description: A high-powered HTTP server with dependency injection, routing and much more.
|
description: A high-powered HTTP server with dependency injection, routing and much more.
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/angel_framework
|
homepage: https://github.com/angel-dart/angel_framework
|
||||||
|
@ -17,7 +17,6 @@ dependencies:
|
||||||
http_server: ^0.9.0
|
http_server: ^0.9.0
|
||||||
http2: ">=0.1.7 <2.0.0"
|
http2: ">=0.1.7 <2.0.0"
|
||||||
logging: ">=0.11.3 <1.0.0"
|
logging: ">=0.11.3 <1.0.0"
|
||||||
lumberjack: ^1.0.0-rc.0
|
|
||||||
matcher: ^0.12.0
|
matcher: ^0.12.0
|
||||||
merge_map: ^1.0.0
|
merge_map: ^1.0.0
|
||||||
meta: ^1.0.0
|
meta: ^1.0.0
|
||||||
|
|
Loading…
Reference in a new issue