Angel3 is no longer printing the request information in the log
insinfo opened this issue · 4 comments
insinfo commented
I noticed that Angel3 is no longer printing the request information in the log as API endpoint and method and HTTP error code as Angel2 did, how can I enable this in Angel3
dukefirehawk commented
The logging should remain the same. Will take a look to see if moving to null safety broke it. Btw, if you could share what request information you saw in the earlier version would be great.
insinfo commented
Angel 2/3 example
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_framework/http.dart';
import 'package:logging/logging.dart';
import 'package:file/local.dart';
import 'package:file/file.dart' as file;
import 'package:angel_static/angel_static.dart' as static_file_server;
main() async {
var app = Angel(), http = AngelHttp(app);
app.logger = Logger('teste')
..onRecord.listen((rec) {
print(rec);
if (rec.error != null) print(rec.error);
if (rec.stackTrace != null) print(rec.stackTrace);
});
await app.configure(configureServer);
await http.startServer('127.0.0.1', 3000);
print('LogRecord listening at ${http.uri}');
}
Future configureServer(Angel app) async {
var fs = const LocalFileSystem();
await app.configure(configureRoutes(fs));
}
AngelConfigurer configureRoutes(file.FileSystem fileSystem) {
return (Angel app) async {
app.get('/', (req, res) => res.write('hello'));
if (!app.environment.isProduction) {
var vDir = static_file_server.VirtualDirectory(
app,
fileSystem,
source: fileSystem.directory('web'),
);
app.fallback(vDir.handleRequest);
}
app.fallback((req, res) => res.write('No exists'));
var oldErrorHandler = app.errorHandler;
app.errorHandler = (e, req, res) async {
if (req.accepts('text/html', strict: true)) {
if (e.statusCode == 404 && req.accepts('text/html', strict: true)) {
await res
.render('error', {'message': 'No file exists at ${req.uri}.'});
} else {
await res.render('error', {'message': e.message});
}
} else {
return await oldErrorHandler(e, req, res);
}
};
};
}
Angel 2 log printing the request information
PS C:\MyDartProjects\angel_exemple> dart .\bin\angel_2.dart
LogRecord listening at http://127.0.0.1:3000
[INFO] teste: 200 GET / (24 ms)
[INFO] teste: 200 GET /favicon.ico (14 ms)
[INFO] teste: 200 GET / (0 ms)
[INFO] teste: 200 GET /favicon.ico (1 ms)
[INFO] teste: 200 GET / (0 ms)
[INFO] teste: 200 GET /favicon.ico (1 ms)
[INFO] teste: 200 GET / (0 ms)
[INFO] teste: 200 GET /favicon.ico (1 ms)
Angel 3 not log print the request information
PS C:\MyDartProjects\angel_exemple> dart .\bin\angel_3.dart
LogRecord listening at http://127.0.0.1:3000
dukefirehawk commented
Fixed in angel3_framework 4.2.4. The log should show up correctly.
To turn the log off manually, just pass in production
flag:
var app = Angel(logger: logger, environment: AngelEnvironment("production"));
Default value is development
.
insinfo commented
@dukefirehawk
I can confirm that it is now working. Thank you very much for the excellent work.