Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: pkg/shelf/lib/src/handlers/logger.dart

Issue 260933004: Support Request hijacking in Shelf, using a similar API to Rack. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/shelf/lib/shelf_io.dart ('k') | pkg/shelf/lib/src/hijack_exception.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library shelf.handlers.logger; 5 library shelf.handlers.logger;
6 6
7 import 'package:stack_trace/stack_trace.dart'; 7 import 'package:stack_trace/stack_trace.dart';
8 8
9 import '../hijack_exception.dart';
9 import '../middleware.dart'; 10 import '../middleware.dart';
10 import '../util.dart'; 11 import '../util.dart';
11 12
12 /// Middleware which prints the time of the request, the elapsed time for the 13 /// Middleware which prints the time of the request, the elapsed time for the
13 /// inner handlers, the response's status code and the request URI. 14 /// inner handlers, the response's status code and the request URI.
14 /// 15 ///
15 /// [logger] takes two paramaters. 16 /// [logger] takes two paramaters.
16 /// 17 ///
17 /// `msg` includes the request time, duration, request method, and requested 18 /// `msg` includes the request time, duration, request method, and requested
18 /// path. 19 /// path.
(...skipping 11 matching lines...) Expand all
30 var watch = new Stopwatch()..start(); 31 var watch = new Stopwatch()..start();
31 32
32 return syncFuture(() => innerHandler(request)).then((response) { 33 return syncFuture(() => innerHandler(request)).then((response) {
33 var msg = _getMessage(startTime, response.statusCode, request.url, 34 var msg = _getMessage(startTime, response.statusCode, request.url,
34 request.method, watch.elapsed); 35 request.method, watch.elapsed);
35 36
36 logger(msg, false); 37 logger(msg, false);
37 38
38 return response; 39 return response;
39 }, onError: (error, stackTrace) { 40 }, onError: (error, stackTrace) {
41 if (error is HijackException) throw error;
42
40 var msg = _getErrorMessage(startTime, request.url, request.method, 43 var msg = _getErrorMessage(startTime, request.url, request.method,
41 watch.elapsed, error, stackTrace); 44 watch.elapsed, error, stackTrace);
42 45
43 logger(msg, true); 46 logger(msg, true);
44 47
45 throw error; 48 throw error;
46 }); 49 });
47 }; 50 };
48 }; 51 };
49 52
(...skipping 19 matching lines...) Expand all
69 return '$msg\n$chain'; 72 return '$msg\n$chain';
70 } 73 }
71 74
72 void _defaultLogger(String msg, bool isError) { 75 void _defaultLogger(String msg, bool isError) {
73 if (isError) { 76 if (isError) {
74 print('[ERROR] $msg'); 77 print('[ERROR] $msg');
75 } else { 78 } else {
76 print(msg); 79 print(msg);
77 } 80 }
78 } 81 }
OLDNEW
« no previous file with comments | « pkg/shelf/lib/shelf_io.dart ('k') | pkg/shelf/lib/src/hijack_exception.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698