Chromium Code Reviews| 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 instrumentation; | 5 library instrumentation; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The interface used by client code to communicate with an instrumentation | 8 * The interface used by client code to communicate with an instrumentation |
| 9 * server. | 9 * server. |
| 10 */ | 10 */ |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 * The interface used by client code to communicate with an instrumentation | 38 * The interface used by client code to communicate with an instrumentation |
| 39 * server by wrapping an [InstrumentationServer]. | 39 * server by wrapping an [InstrumentationServer]. |
| 40 */ | 40 */ |
| 41 class InstrumentationService { | 41 class InstrumentationService { |
| 42 /** | 42 /** |
| 43 * An instrumentation service that will not log any instrumentation data. | 43 * An instrumentation service that will not log any instrumentation data. |
| 44 */ | 44 */ |
| 45 static final InstrumentationService NULL_SERVICE = | 45 static final InstrumentationService NULL_SERVICE = |
| 46 new InstrumentationService(null); | 46 new InstrumentationService(null); |
| 47 | 47 |
| 48 static const String TAG_EXCEPTION = 'Ex'; | |
| 48 static const String TAG_NOTIFICATION = 'Noti'; | 49 static const String TAG_NOTIFICATION = 'Noti'; |
| 49 static const String TAG_REQUEST = 'Req'; | 50 static const String TAG_REQUEST = 'Req'; |
| 50 static const String TAG_RESPONSE = 'Res'; | 51 static const String TAG_RESPONSE = 'Res'; |
| 51 static const String TAG_VERSION = 'Ver'; | 52 static const String TAG_VERSION = 'Ver'; |
| 52 | 53 |
| 53 /** | 54 /** |
| 54 * The instrumentation server used to communicate with the server, or `null` | 55 * The instrumentation server used to communicate with the server, or `null` |
| 55 * if instrumentation data should not be logged. | 56 * if instrumentation data should not be logged. |
| 56 */ | 57 */ |
| 57 InstrumentationServer _instrumentationServer; | 58 InstrumentationServer _instrumentationServer; |
| 58 | 59 |
| 59 /** | 60 /** |
| 60 * Initialize a newly created instrumentation service to comunicate with the | 61 * Initialize a newly created instrumentation service to comunicate with the |
| 61 * given [instrumentationServer]. | 62 * given [instrumentationServer]. |
| 62 */ | 63 */ |
| 63 InstrumentationService(this._instrumentationServer); | 64 InstrumentationService(this._instrumentationServer); |
| 64 | 65 |
| 65 /** | 66 /** |
| 66 * The current time, expressed as a decimal encoded number of milliseconds. | 67 * The current time, expressed as a decimal encoded number of milliseconds. |
| 67 */ | 68 */ |
| 68 String get _timestamp => new DateTime.now().millisecond.toString(); | 69 String get _timestamp => new DateTime.now().millisecondsSinceEpoch.toString(); |
| 70 | |
| 71 /** | |
| 72 * Log that the given [exception] was thrown, with the given [stackTrace]. | |
| 73 */ | |
| 74 void logException(dynamic exception, StackTrace stackTrace) { | |
| 75 if (_instrumentationServer != null) { | |
| 76 String message = _toString(exception); | |
| 77 String trace = _toString(stackTrace); | |
| 78 _instrumentationServer.logWithPriority( | |
| 79 '$_timestamp:$TAG_EXCEPTION:$message:$trace'); | |
|
Paul Berry
2014/12/19 17:07:51
Should "$message" be escaped in any way to make it
Brian Wilkerson
2014/12/19 17:10:47
Good question. I thought about other special chara
| |
| 80 } | |
| 81 } | |
| 69 | 82 |
| 70 /** | 83 /** |
| 71 * Log that a notification has been sent to the client. | 84 * Log that a notification has been sent to the client. |
| 72 */ | 85 */ |
| 73 void logNotification(String notification) { | 86 void logNotification(String notification) { |
| 74 _log(TAG_NOTIFICATION, notification); | 87 _log(TAG_NOTIFICATION, notification); |
| 75 } | 88 } |
| 76 | 89 |
| 77 /** | 90 /** |
| 78 * Log that a request has been sent to the client. | 91 * Log that a request has been sent to the client. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 101 } | 114 } |
| 102 | 115 |
| 103 /** | 116 /** |
| 104 * Log the given message with the given tag. | 117 * Log the given message with the given tag. |
| 105 */ | 118 */ |
| 106 void _log(String tag, String message) { | 119 void _log(String tag, String message) { |
| 107 if (_instrumentationServer != null) { | 120 if (_instrumentationServer != null) { |
| 108 _instrumentationServer.log('$_timestamp:$tag:$message'); | 121 _instrumentationServer.log('$_timestamp:$tag:$message'); |
| 109 } | 122 } |
| 110 } | 123 } |
| 124 | |
| 125 /** | |
| 126 * Convert the given [object] to a string. | |
| 127 */ | |
| 128 String _toString(Object object) { | |
| 129 if (object == null) { | |
| 130 return 'null'; | |
| 131 } | |
| 132 return object.toString(); | |
| 133 } | |
| 111 } | 134 } |
| OLD | NEW |