Skip to content

Commit 924ec34

Browse files
MichaelRFairhurstcommit-bot@chromium.org
authored andcommitted
Remove analysis logger, replace with calls to InstrumentationService
Change-Id: Ifddd58b731aa0af8f76a91261757997dc52a9fc7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123328 Commit-Queue: Mike Fairhurst <mfairhurst@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
1 parent 09bc0cc commit 924ec34

File tree

31 files changed

+197
-271
lines changed

31 files changed

+197
-271
lines changed

pkg/analysis_server/lib/src/analysis_logger.dart

Lines changed: 0 additions & 55 deletions
This file was deleted.

pkg/analysis_server/lib/src/analysis_server.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import 'package:analysis_server/protocol/protocol_constants.dart'
1313
show PROTOCOL_VERSION;
1414
import 'package:analysis_server/protocol/protocol_generated.dart'
1515
hide AnalysisOptions;
16-
import 'package:analysis_server/src/analysis_logger.dart';
1716
import 'package:analysis_server/src/analysis_server_abstract.dart';
1817
import 'package:analysis_server/src/channel/channel.dart';
1918
import 'package:analysis_server/src/computer/computer_highlights.dart';
@@ -241,7 +240,6 @@ class AnalysisServer extends AbstractAnalysisServer {
241240
ServerContextManagerCallbacks contextManagerCallbacks =
242241
new ServerContextManagerCallbacks(this, resourceProvider);
243242
contextManager.callbacks = contextManagerCallbacks;
244-
AnalysisEngine.instance.logger = new AnalysisLogger(this);
245243
_onAnalysisStartedController = new StreamController.broadcast();
246244
onAnalysisStarted.first.then((_) {
247245
onAnalysisComplete.then((_) {
@@ -897,7 +895,8 @@ class ServerContextManagerCallbacks extends ContextManagerCallbacks {
897895
if (result.contextKey != null) {
898896
message += ' context: ${result.contextKey}';
899897
}
900-
AnalysisEngine.instance.logger.logError(message, result.exception);
898+
AnalysisEngine.instance.instrumentationService.logException(
899+
new CaughtException.wrapInMessage(message, result.exception));
901900
});
902901
analysisServer.driverMap[folder] = analysisDriver;
903902
return analysisDriver;

pkg/analysis_server/lib/src/analysis_server_abstract.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ abstract class AbstractAnalysisServer {
110110
_analyzedFilesGlobs
111111
.add(new Glob(resourceProvider.pathContext.separator, pattern));
112112
} catch (exception, stackTrace) {
113-
AnalysisEngine.instance.logger.logError(
114-
'Invalid glob pattern: "$pattern"',
115-
new CaughtException(exception, stackTrace));
113+
AnalysisEngine.instance.instrumentationService.logException(
114+
new CaughtException.withMessage(
115+
'Invalid glob pattern: "$pattern"', exception, stackTrace));
116116
}
117117
}
118118
}

pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,8 @@ class LspServerContextManagerCallbacks extends ContextManagerCallbacks {
625625
if (result.contextKey != null) {
626626
message += ' context: ${result.contextKey}';
627627
}
628-
AnalysisEngine.instance.logger.logError(message, result.exception);
628+
AnalysisEngine.instance.instrumentationService.logException(
629+
new CaughtException.wrapInMessage(message, result.exception));
629630
});
630631
analysisServer.driverMap[folder] = analysisDriver;
631632
return analysisDriver;

pkg/analysis_server/test/abstract_context.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ test:file:///home/test/lib
202202

203203
void tearDown() {
204204
AnalysisEngine.instance.clearCaches();
205-
AnalysisEngine.instance.logger = null;
206205
}
207206

208207
/// Update `/home/test/pubspec.yaml` and create the driver.

pkg/analysis_server/test/context_manager_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:analysis_server/src/context_manager.dart';
88
import 'package:analysis_server/src/plugin/notification_manager.dart';
99
import 'package:analysis_server/src/utilities/null_string_sink.dart';
1010
import 'package:analyzer/error/error.dart';
11+
import 'package:analyzer/exception/exception.dart';
1112
import 'package:analyzer/file_system/file_system.dart';
1213
import 'package:analyzer/instrumentation/instrumentation.dart';
1314
import 'package:analyzer/source/error_processor.dart';
@@ -2509,8 +2510,9 @@ class TestContextManagerCallbacks extends ContextManagerCallbacks {
25092510

25102511
driverMap[path] = currentDriver;
25112512
currentDriver.exceptions.listen((ExceptionResult result) {
2512-
AnalysisEngine.instance.logger
2513-
.logError('Analysis failed: ${result.path}', result.exception);
2513+
AnalysisEngine.instance.instrumentationService.logException(
2514+
new CaughtException.wrapInMessage(
2515+
'Analysis failed: ${result.path}', result.exception));
25142516
});
25152517
return currentDriver;
25162518
}

pkg/analyzer/lib/exception/exception.dart

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ class CaughtException implements Exception {
4444
*/
4545
final Object exception;
4646

47+
/**
48+
* The message describing where/how/why this was caught.
49+
*/
50+
final String message;
51+
4752
/**
4853
* The stack trace associated with the exception.
4954
*/
@@ -53,16 +58,21 @@ class CaughtException implements Exception {
5358
* Initialize a newly created caught exception to have the given [exception]
5459
* and [stackTrace].
5560
*/
56-
CaughtException(this.exception, stackTrace) {
57-
if (stackTrace == null) {
58-
try {
59-
throw this;
60-
} catch (_, st) {
61-
stackTrace = st;
62-
}
63-
}
64-
this.stackTrace = stackTrace;
65-
}
61+
CaughtException(exception, stackTrace)
62+
: this.withMessage(null, exception, stackTrace);
63+
64+
/**
65+
* Initialize a newly created caught exception to have the given [exception],
66+
* [stackTrace], and [message].
67+
*/
68+
CaughtException.withMessage(this.message, this.exception, stackTrace)
69+
: this.stackTrace = stackTrace ?? StackTrace.current;
70+
71+
/**
72+
* Create a [CaughtException] to wrap a prior one, adding a [message].
73+
*/
74+
CaughtException.wrapInMessage(String message, CaughtException exception)
75+
: this.withMessage(message, exception, null);
6676

6777
@override
6878
String toString() {
@@ -76,6 +86,9 @@ class CaughtException implements Exception {
7686
* stack trace.
7787
*/
7888
void _writeOn(StringBuffer buffer) {
89+
if (message != null) {
90+
buffer.writeln(message);
91+
}
7992
if (exception is AnalysisException) {
8093
AnalysisException analysisException = exception;
8194
buffer.writeln(analysisException.message);

pkg/analyzer/lib/instrumentation/instrumentation.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class InstrumentationService {
131131
* Log that the given non-priority [exception] was thrown, with the given
132132
* [stackTrace].
133133
*/
134-
void logException(dynamic exception, StackTrace stackTrace) {
134+
void logException(dynamic exception, [StackTrace stackTrace]) {
135135
if (_instrumentationServer != null) {
136136
String message = _toString(exception);
137137
String trace = _toString(stackTrace);
@@ -154,7 +154,8 @@ class InstrumentationService {
154154
/**
155155
* Log unstructured text information for debugging purposes.
156156
*/
157-
void logInfo(String message) => _log(TAG_INFO, message);
157+
void logInfo(String message, [dynamic exception]) =>
158+
_log(TAG_INFO, message + (exception == null ? "" : _toString(exception)));
158159

159160
/**
160161
* Log that a log entry that was written to the analysis engine's log. The log

pkg/analyzer/lib/src/context/source.dart

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,21 @@ class SourceFactoryImpl implements SourceFactory {
9898
@override
9999
Source forUri(String absoluteUri) {
100100
try {
101-
Uri uri = Uri.parse(absoluteUri);
101+
Uri uri;
102+
try {
103+
uri = Uri.parse(absoluteUri);
104+
} catch (exception, stackTrace) {
105+
AnalysisEngine.instance.instrumentationService
106+
.logInfo('Could not resolve URI: $absoluteUri $stackTrace');
107+
return null;
108+
}
102109
if (uri.isAbsolute) {
103110
return _internalResolveUri(null, uri);
104111
}
105112
} catch (exception, stackTrace) {
106-
AnalysisEngine.instance.logger.logError(
107-
"Could not resolve URI: $absoluteUri",
108-
new CaughtException(exception, stackTrace));
113+
AnalysisEngine.instance.instrumentationService.logException(
114+
new CaughtException.withMessage(
115+
"Could not resolve URI: $absoluteUri", exception, stackTrace));
109116
}
110117
return null;
111118
}
@@ -116,9 +123,9 @@ class SourceFactoryImpl implements SourceFactory {
116123
try {
117124
return _internalResolveUri(null, absoluteUri);
118125
} on AnalysisException catch (exception, stackTrace) {
119-
AnalysisEngine.instance.logger.logError(
120-
"Could not resolve URI: $absoluteUri",
121-
new CaughtException(exception, stackTrace));
126+
AnalysisEngine.instance.instrumentationService.logException(
127+
new CaughtException.withMessage(
128+
"Could not resolve URI: $absoluteUri", exception, stackTrace));
122129
}
123130
}
124131
return null;
@@ -137,10 +144,12 @@ class SourceFactoryImpl implements SourceFactory {
137144
} catch (exception, stackTrace) {
138145
String containingFullName =
139146
containingSource != null ? containingSource.fullName : '<null>';
140-
AnalysisEngine.instance.logger.logInformation(
141-
"Could not resolve URI ($containedUri) "
142-
"relative to source ($containingFullName)",
143-
new CaughtException(exception, stackTrace));
147+
AnalysisEngine.instance.instrumentationService
148+
.logException(new CaughtException.withMessage(
149+
"Could not resolve URI ($containedUri) "
150+
"relative to source ($containingFullName)",
151+
exception,
152+
stackTrace));
144153
return null;
145154
}
146155
}

pkg/analyzer/lib/src/dart/ast/ast.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,9 @@ class AssignmentExpressionImpl extends ExpressionImpl
647647
} else {
648648
message = "The right-hand size is null";
649649
}
650-
AnalysisEngine.instance.logger.logError(
651-
message, new CaughtException(new AnalysisException(message), null));
650+
AnalysisEngine.instance.instrumentationService.logException(
651+
new CaughtException(new AnalysisException(message), null),
652+
StackTrace.current);
652653
}
653654
_leftHandSide = _becomeParentOf(leftHandSide);
654655
_rightHandSide = _becomeParentOf(rightHandSide);

0 commit comments

Comments
 (0)