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

Side by Side Diff: pkg/analyzer/lib/instrumentation/instrumentation.dart

Issue 835213002: Escape field separator (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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 | « no previous file | pkg/analyzer/test/instrumentation/instrumentation_test.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 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 78
79 /** 79 /**
80 * Log that the given non-priority [exception] was thrown, with the given 80 * Log that the given non-priority [exception] was thrown, with the given
81 * [stackTrace]. 81 * [stackTrace].
82 */ 82 */
83 void logException(dynamic exception, StackTrace stackTrace) { 83 void logException(dynamic exception, StackTrace stackTrace) {
84 if (_instrumentationServer != null) { 84 if (_instrumentationServer != null) {
85 String message = _toString(exception); 85 String message = _toString(exception);
86 String trace = _toString(stackTrace); 86 String trace = _toString(stackTrace);
87 _instrumentationServer.log('$_timestamp:$TAG_EXCEPTION:$message:$trace'); 87 _instrumentationServer.log(_join([TAG_EXCEPTION, message, trace]));
88 } 88 }
89 } 89 }
90 90
91 /** 91 /**
92 * Log that a notification has been sent to the client. 92 * Log that a notification has been sent to the client.
93 */ 93 */
94 void logNotification(String notification) { 94 void logNotification(String notification) {
95 _log(TAG_NOTIFICATION, notification); 95 _log(TAG_NOTIFICATION, notification);
96 } 96 }
97 97
98 /** 98 /**
99 * Log that the given priority [exception] was thrown, with the given 99 * Log that the given priority [exception] was thrown, with the given
100 * [stackTrace]. 100 * [stackTrace].
101 */ 101 */
102 void logPriorityException(dynamic exception, StackTrace stackTrace) { 102 void logPriorityException(dynamic exception, StackTrace stackTrace) {
103 if (_instrumentationServer != null) { 103 if (_instrumentationServer != null) {
104 String message = _toString(exception); 104 String message = _toString(exception);
105 String trace = _toString(stackTrace); 105 String trace = _toString(stackTrace);
106 _instrumentationServer.logWithPriority( 106 _instrumentationServer.logWithPriority(
107 '$_timestamp:$TAG_EXCEPTION:$message:$trace'); 107 _join([TAG_EXCEPTION, message, trace]));
108 } 108 }
109 } 109 }
110 110
111 /** 111 /**
112 * Log that a request has been sent to the client. 112 * Log that a request has been sent to the client.
113 */ 113 */
114 void logRequest(String request) { 114 void logRequest(String request) {
115 _log(TAG_REQUEST, request); 115 _log(TAG_REQUEST, request);
116 } 116 }
117 117
(...skipping 10 matching lines...) Expand all
128 * should be invoked on this instance after this method has been invoked. 128 * should be invoked on this instance after this method has been invoked.
129 */ 129 */
130 void shutdown() { 130 void shutdown() {
131 if (_instrumentationServer != null) { 131 if (_instrumentationServer != null) {
132 _instrumentationServer.shutdown(); 132 _instrumentationServer.shutdown();
133 _instrumentationServer = null; 133 _instrumentationServer = null;
134 } 134 }
135 } 135 }
136 136
137 /** 137 /**
138 * Write an escaped version of the given [string] to the given [buffer].
139 */
140 void _escape(StringBuffer buffer, String field) {
141 int index = field.indexOf(':');
142 if (index < 0) {
143 buffer.write(field);
144 return;
145 }
146 int start = 0;
147 while (index > 0) {
148 buffer.write(field.substring(start, index));
149 buffer.write('::');
150 start = index + 1;
151 index = field.indexOf(':', start);
152 }
153 buffer.write(field.substring(start));
154 }
155
156 /**
157 * Return the result of joining the values of the given fields, escaping the
158 * separator character by doubling it.
159 */
160 String _join(List<String> fields) {
161 StringBuffer buffer = new StringBuffer();
162 buffer.write(_timestamp);
163 for (String field in fields) {
164 buffer.write(':');
165 _escape(buffer, field);
166 }
167 return buffer.toString();
168 }
169
170 /**
138 * Log the given message with the given tag. 171 * Log the given message with the given tag.
139 */ 172 */
140 void _log(String tag, String message) { 173 void _log(String tag, String message) {
141 if (_instrumentationServer != null) { 174 if (_instrumentationServer != null) {
142 _instrumentationServer.log('$_timestamp:$tag:$message'); 175 _instrumentationServer.log(_join([tag, message]));
143 } 176 }
144 } 177 }
145 178
146 /** 179 /**
147 * Convert the given [object] to a string. 180 * Convert the given [object] to a string.
148 */ 181 */
149 String _toString(Object object) { 182 String _toString(Object object) {
150 if (object == null) { 183 if (object == null) {
151 return 'null'; 184 return 'null';
152 } 185 }
153 return object.toString(); 186 return object.toString();
154 } 187 }
155 } 188 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/instrumentation/instrumentation_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698