logger function
Middleware
logger()
Logger middleware
Implementation
Middleware logger() {
return (Handler innerHandler) {
return (Request request) async {
final stopwatch = Stopwatch()..start();
final response = await innerHandler(request);
stopwatch.stop();
final status = response.statusCode;
final color = status < 400 ? '\x1B[32m' : '\x1B[31m';
print('${request.method} ${request.url.path} $color$status\x1B[0m ${stopwatch.elapsedMilliseconds}ms');
return response;
};
};
}