refactor(dart/transform): Improve logging

Ensure that, where possible, log messages include an [AssetId].

Closes #5369
This commit is contained in:
Tim Blasi 2015-11-17 16:27:29 -08:00 committed by Timothy Blasi
parent cee67e6fe0
commit 9ae171e0c8
8 changed files with 37 additions and 22 deletions

View File

@ -56,8 +56,10 @@ class ReflectionInfoVisitor extends RecursiveAstVisitor<ReflectionInfoModel> {
if (numCtorsFound > 1) {
var ctorName = ctor.name;
if (ctorName != null) {
log.warning('Found ${numCtorsFound} constructors for class '
'${node.name}; using constructor ${ctorName}.');
log.warning(
'Found ${numCtorsFound} constructors for class '
'${node.name}; using constructor ${ctorName}.',
asset: assetId);
}
}
return ctor;
@ -166,8 +168,10 @@ class ReflectionInfoVisitor extends RecursiveAstVisitor<ReflectionInfoModel> {
if (directivesNode == null) return const [];
if (directivesNode.expression is! ListLiteral) {
log.warning('Angular 2 expects a list literal for `directives` '
'but found a ${directivesNode.expression.runtimeType}');
log.warning(
'Angular 2 expects a list literal for `directives` '
'but found a ${directivesNode.expression.runtimeType}',
asset: assetId);
return const [];
}
final directives = <PrefixedDirective>[];
@ -179,7 +183,8 @@ class ReflectionInfoVisitor extends RecursiveAstVisitor<ReflectionInfoModel> {
} else if (dep is Identifier) {
directives.add(new PrefixedDirective()..name = '${dep}');
} else {
log.warning('Found unexpected value $dep in `directives`.');
log.warning('Found unexpected value $dep in `directives`.',
asset: assetId);
}
}
return directives;

View File

@ -114,12 +114,13 @@ class _FindDeferredLibraries extends Object with RecursiveAstVisitor<Object> {
bool hasDeferredLibrariesToRewrite() {
if (deferredImports.isEmpty) {
log.fine('There are no deferred library imports.');
log.fine('There are no deferred library imports.', asset: _entryPoint);
return false;
}
if (loadLibraryInvocations.isEmpty) {
log.fine(
'There are no loadLibrary invocations that need to be rewritten.');
'There are no loadLibrary invocations that need to be rewritten.',
asset: _entryPoint);
return false;
}
return true;

View File

@ -72,9 +72,11 @@ Future<Map<String, String>> _processNgImports(NgDepsModel model,
retVal[directive.uri] = summaryJsonUri;
}
}, onError: (err, stack) {
log.warning('Error while looking for $summaryJsonUri. '
log.warning(
'Error while looking for $summaryJsonUri. '
'Message: $err\n'
'Stack: $stack');
'Stack: $stack',
asset: assetId);
});
}))
.then((_) => retVal);

View File

@ -77,7 +77,7 @@ Future _linkRecursive(NgMeta ngMeta, AssetReader reader, AssetId assetId,
}
} catch (err, st) {
// Log and continue.
log.warning('Failed to fetch $uri. Message: $err.\n$st');
log.warning('Failed to fetch $uri. Message: $err.\n$st', asset: assetId);
}
}));
}

View File

@ -96,7 +96,7 @@ class _NgMetaVisitor extends Object with SimpleAstVisitor<Object> {
compileDirectiveMetadata;
}
}).catchError((err) {
log.error('ERROR: $err');
log.error('ERROR: $err', asset: assetId);
}));
return null;
}

View File

@ -179,7 +179,7 @@ class _ViewPropInliner extends RecursiveAstVisitor<Object> {
final inlinedVal = _addInlineValue(url, varBase: _inlinedStyleBase);
_writer.print('${inlinedVal.name},');
} else {
zone.log.warning('style url is not a String (${url})');
zone.log.warning('style url is not a String (${url})', asset: _assetId);
}
}
_writer.print(']');
@ -191,7 +191,8 @@ class _ViewPropInliner extends RecursiveAstVisitor<Object> {
void _populateTemplateUrl(NamedExpression node) {
var url = naiveEval(node.expression);
if (url is! String) {
zone.log.warning('template url is not a String (${node.expression})');
zone.log.warning('template url is not a String (${node.expression})',
asset: _assetId);
return;
}
_writer.print(_code.substring(_lastIndex, node.offset));
@ -209,7 +210,7 @@ class _ViewPropInliner extends RecursiveAstVisitor<Object> {
final resolvedUri = _urlResolver.resolve(_baseUri.toString(), url);
return _xhr.get(resolvedUri).catchError((_) {
zone.log.error('$_baseUri: could not read $url');
zone.log.error('$_baseUri: could not read $url', asset: _assetId);
return '';
});
}

View File

@ -44,9 +44,11 @@ class ReflectionRemover extends Transformer implements LazyTransformer {
if (options.modeName == TRANSFORM_DYNAMIC_MODE) {
mirrorMode = MirrorMode.debug;
writeStaticInit = false;
zone.log.info('Running in "${options.modeName}", '
zone.log.info(
'Running in "${options.modeName}", '
'mirrorMode: ${mirrorMode}, '
'writeStaticInit: ${writeStaticInit}.');
'writeStaticInit: ${writeStaticInit}.',
asset: primaryId);
}
var transformedCode = await removeReflectionCapabilities(

View File

@ -19,8 +19,8 @@ import 'package:barback/barback.dart';
///
/// The returned value wraps the [NgDepsModel] at `assetId` as well as these
/// created objects.
Future<CompileDataResults> createCompileData(
AssetReader reader, AssetId assetId, List<String> platformDirectives) async {
Future<CompileDataResults> createCompileData(AssetReader reader,
AssetId assetId, List<String> platformDirectives) async {
return logElapsedAsync(() async {
final creator =
await _CompileDataCreator.create(reader, assetId, platformDirectives);
@ -92,10 +92,12 @@ class _CompileDataCreator {
} else if (depNgMeta.aliases.containsKey(dep.name)) {
compileDatum.directives.addAll(depNgMeta.flatten(dep.name));
} else {
log.warning('Could not find Directive entry for $dep. '
log.warning(
'Could not find Directive entry for $dep. '
'Please be aware that Dart transformers have limited support for '
'reusable, pre-defined lists of Directives (aka '
'"directive aliases"). See https://goo.gl/d8XPt0 for details.');
'"directive aliases"). See https://goo.gl/d8XPt0 for details.',
asset: entryPoint);
}
}
compileData[reflectable] = compileDatum;
@ -112,8 +114,10 @@ class _CompileDataCreator {
for (var ad in platformDirectives) {
final parts = ad.split("#");
if (parts.length != 2) {
log.warning('The platform directives configuration option '
'must be in the following format: "URI#TOKEN"');
log.warning(
'The platform directives configuration option '
'must be in the following format: "URI#TOKEN"',
asset: entryPoint);
return const [];
}
res.addAll(await _readPlatformDirectivesFromUri(parts[0], parts[1]));