Update logging logic

This commit is contained in:
Tobe O 2018-06-26 16:50:49 -04:00
parent 4324d80acc
commit b3baeb7297

View file

@ -25,16 +25,13 @@ void isolateMain(int id) {
// Alternatives include sending logs to a service like Sentry. // Alternatives include sending logs to a service like Sentry.
app.logger = new Logger('angel') app.logger = new Logger('angel')
..onRecord.listen((rec) { ..onRecord.listen((rec) {
if (rec.error != null) { if (rec.error == null) {
stdout.writeln(rec);
} else {
var err = rec.error; var err = rec.error;
if (err is AngelHttpException && err.statusCode != 500) return; if (err is AngelHttpException && err.statusCode != 500) return;
var now = new DateTime.now().toUtc(); var sink = stderr;
var filename = 'server_log_' + now.toString() + '.txt'; sink..writeln(rec)..writeln(rec.error)..writeln(rec.stackTrace);
var sink = new File(filename).openWrite(mode: FileMode.append);
sink
..writeln(rec.error)
..writeln(rec.stackTrace)
..close();
} }
}); });
@ -44,7 +41,7 @@ void isolateMain(int id) {
// This effectively lets us multi-thread the application. // This effectively lets us multi-thread the application.
var http = new AngelHttp.custom(app, startShared); var http = new AngelHttp.custom(app, startShared);
var server = await http.startServer(hostname, port); var server = await http.startServer(hostname, port);
print( print('Instance #$id listening at http://${server.address.address}:${server
'Instance #$id listening at http://${server.address.address}:${server.port}'); .port}');
}); });
} }