| Index: pkg/analyzer/lib/instrumentation/instrumentation.dart
|
| diff --git a/pkg/analyzer/lib/instrumentation/instrumentation.dart b/pkg/analyzer/lib/instrumentation/instrumentation.dart
|
| index 7557ecd3553e0934c1b77b1bafbc7090c6e81ac2..5075dd8abf8d06259208bfb04658b199c9cd1c1a 100644
|
| --- a/pkg/analyzer/lib/instrumentation/instrumentation.dart
|
| +++ b/pkg/analyzer/lib/instrumentation/instrumentation.dart
|
| @@ -12,10 +12,21 @@ abstract class InstrumentationServer {
|
| /**
|
| * Pass the given [message] to the instrumentation server so that it will be
|
| * logged with other messages.
|
| + *
|
| + * This method should be used for most logging.
|
| */
|
| void log(String message);
|
|
|
| /**
|
| + * Pass the given [message] to the instrumentation server so that it will be
|
| + * logged with other messages.
|
| + *
|
| + * This method should only be used for logging high priority messages, such as
|
| + * exceptions that cause the server to shutdown.
|
| + */
|
| + void logWithPriority(String message);
|
| +
|
| + /**
|
| * Signal that the client is done communicating with the instrumentation
|
| * server. This method should be invoked exactly one time and no other methods
|
| * should be invoked on this instance after this method has been invoked.
|
| @@ -24,21 +35,75 @@ abstract class InstrumentationServer {
|
| }
|
|
|
| /**
|
| - * An [InstrumentationServer] that ignores all instrumentation requests sent to
|
| - * it. It can be used when no instrumentation data is to be collected as a way
|
| - * to avoid needing to check for null values.
|
| + * The interface used by client code to communicate with an instrumentation
|
| + * server by wrapping an [InstrumentationServer].
|
| */
|
| -class NullInstrumentationServer implements InstrumentationServer {
|
| +class InstrumentationService {
|
| + /**
|
| + * An instrumentation service that will not log any instrumentation data.
|
| + */
|
| + static const InstrumentationService NULL_SERVICE =
|
| + const InstrumentationService(null);
|
| +
|
| + static const String TAG_NOTIFICATION = 'Noti';
|
| + static const String TAG_REQUEST = 'Req';
|
| + static const String TAG_RESPONSE = 'Res';
|
| + static const String TAG_VERSION = 'Ver';
|
| + /**
|
| + * The instrumentation server used to communicate with the server, or `null`
|
| + * if instrumentation data should not be logged.
|
| + */
|
| + final InstrumentationServer instrumentationServer;
|
| +
|
| + /**
|
| + * Initialize a newly created instrumentation service to comunicate with the
|
| + * given instrumentation server.
|
| + */
|
| + const InstrumentationService(this.instrumentationServer);
|
| +
|
| + /**
|
| + * The current time, expressed as a decimal encoded number of milliseconds.
|
| + */
|
| + String get _timestamp => new DateTime.now().millisecond.toString();
|
| +
|
| /**
|
| - * Initialize a newly created instance of this class.
|
| + * Log that a notification has been sent to the client.
|
| */
|
| - const NullInstrumentationServer();
|
| + void logNotification(String notification) {
|
| + _log(TAG_NOTIFICATION, notification);
|
| + }
|
|
|
| - @override
|
| - void log(String message) {
|
| + /**
|
| + * Log that a request has been sent to the client.
|
| + */
|
| + void logRequest(String request) {
|
| + _log(TAG_REQUEST, request);
|
| }
|
|
|
| - @override
|
| + /**
|
| + * Log that a response has been sent to the client.
|
| + */
|
| + void logResponse(String response) {
|
| + _log(TAG_RESPONSE, response);
|
| + }
|
| +
|
| + /**
|
| + * Signal that the client is done communicating with the instrumentation
|
| + * server. This method should be invoked exactly one time and no other methods
|
| + * should be invoked on this instance after this method has been invoked.
|
| + */
|
| void shutdown() {
|
| + if (instrumentationServer != null) {
|
| + instrumentationServer.shutdown();
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * Log the given message with the given tag.
|
| + */
|
| + void _log(String tag, String message) {
|
| + if (instrumentationServer != null) {
|
| + instrumentationServer.log('$_timestamp:$tag:$message');
|
| + }
|
| }
|
| }
|
|
|