| OLD | NEW |
| 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 '../hijack_exception.dart'; |
| 10 import '../middleware.dart'; | 10 import '../middleware.dart'; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 var msg = _getErrorMessage(startTime, request.url, request.method, | 43 var msg = _getErrorMessage(startTime, request.url, request.method, |
| 44 watch.elapsed, error, stackTrace); | 44 watch.elapsed, error, stackTrace); |
| 45 | 45 |
| 46 logger(msg, true); | 46 logger(msg, true); |
| 47 | 47 |
| 48 throw error; | 48 throw error; |
| 49 }); | 49 }); |
| 50 }; | 50 }; |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 String _getMessage(DateTime requestTime, int statusCode, Uri url, | 53 String _getMessage(DateTime requestTime, int statusCode, Uri url, String method, |
| 54 String method, Duration elapsedTime) { | 54 Duration elapsedTime) { |
| 55 | |
| 56 return '${requestTime}\t$elapsedTime\t$method\t[${statusCode}]\t${url}'; | 55 return '${requestTime}\t$elapsedTime\t$method\t[${statusCode}]\t${url}'; |
| 57 } | 56 } |
| 58 | 57 |
| 59 String _getErrorMessage(DateTime requestTime, Uri url, | 58 String _getErrorMessage(DateTime requestTime, Uri url, String method, |
| 60 String method, Duration elapsedTime, Object error, StackTrace stack) { | 59 Duration elapsedTime, Object error, StackTrace stack) { |
| 61 | |
| 62 var chain = new Chain.current(); | 60 var chain = new Chain.current(); |
| 63 if (stack != null) { | 61 if (stack != null) { |
| 64 chain = new Chain.forTrace(stack) | 62 chain = new Chain.forTrace(stack) |
| 65 .foldFrames((frame) => frame.isCore || frame.package == 'shelf') | 63 .foldFrames((frame) => frame.isCore || frame.package == 'shelf').terse; |
| 66 .terse; | |
| 67 } | 64 } |
| 68 | 65 |
| 69 var msg = '${requestTime}\t$elapsedTime\t$method\t${url}\n$error'; | 66 var msg = '${requestTime}\t$elapsedTime\t$method\t${url}\n$error'; |
| 70 if(chain == null) return msg; | 67 if (chain == null) return msg; |
| 71 | 68 |
| 72 return '$msg\n$chain'; | 69 return '$msg\n$chain'; |
| 73 } | 70 } |
| 74 | 71 |
| 75 void _defaultLogger(String msg, bool isError) { | 72 void _defaultLogger(String msg, bool isError) { |
| 76 if (isError) { | 73 if (isError) { |
| 77 print('[ERROR] $msg'); | 74 print('[ERROR] $msg'); |
| 78 } else { | 75 } else { |
| 79 print(msg); | 76 print(msg); |
| 80 } | 77 } |
| 81 } | 78 } |
| OLD | NEW |