2015-03-20 15:37:09 -07:00
|
|
|
library angular2.transform.common.logging;
|
2015-02-19 12:00:09 -08:00
|
|
|
|
2015-04-13 16:54:09 -07:00
|
|
|
import 'dart:async';
|
2015-02-19 12:00:09 -08:00
|
|
|
import 'package:barback/barback.dart';
|
|
|
|
import 'package:code_transformers/messages/build_logger.dart';
|
2015-04-13 16:54:09 -07:00
|
|
|
import 'package:source_span/source_span.dart';
|
2015-02-19 12:00:09 -08:00
|
|
|
|
|
|
|
BuildLogger _logger;
|
|
|
|
|
|
|
|
/// Prepares [logger] for use throughout the transformer.
|
|
|
|
void init(Transform t) {
|
2015-02-27 14:42:21 -08:00
|
|
|
_logger = new BuildLogger(t);
|
2015-02-19 12:00:09 -08:00
|
|
|
}
|
|
|
|
|
2015-03-18 11:03:41 -07:00
|
|
|
/// Sets [logger] directly. Used for testing - in general use [init].
|
|
|
|
void setLogger(BuildLogger logger) {
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2015-02-19 12:00:09 -08:00
|
|
|
/// The logger the transformer should use for messaging.
|
|
|
|
BuildLogger get logger {
|
|
|
|
if (_logger == null) {
|
2015-04-09 17:42:14 -07:00
|
|
|
_logger = new PrintLogger();
|
2015-02-19 12:00:09 -08:00
|
|
|
}
|
|
|
|
return _logger;
|
|
|
|
}
|
2015-04-09 17:42:14 -07:00
|
|
|
|
|
|
|
class PrintLogger implements BuildLogger {
|
2015-04-13 16:54:09 -07:00
|
|
|
@override
|
|
|
|
final String detailsUri = '';
|
|
|
|
@override
|
|
|
|
final bool convertErrorsToWarnings = false;
|
|
|
|
|
2015-04-09 17:42:14 -07:00
|
|
|
void _printWithPrefix(prefix, msg) => print('$prefix: $msg');
|
|
|
|
void info(msg, {AssetId asset, SourceSpan span}) =>
|
|
|
|
_printWithPrefix('INFO', msg);
|
|
|
|
void fine(msg, {AssetId asset, SourceSpan span}) =>
|
|
|
|
_printWithPrefix('FINE', msg);
|
|
|
|
void warning(msg, {AssetId asset, SourceSpan span}) =>
|
|
|
|
_printWithPrefix('WARN', msg);
|
|
|
|
void error(msg, {AssetId asset, SourceSpan span}) {
|
|
|
|
throw new PrintLoggerError(msg, asset, span);
|
|
|
|
}
|
|
|
|
Future writeOutput() => null;
|
|
|
|
Future addLogFilesFromAsset(AssetId id, [int nextNumber = 1]) => null;
|
|
|
|
}
|
|
|
|
|
|
|
|
class PrintLoggerError extends Error {
|
|
|
|
final String message;
|
|
|
|
final AssetId asset;
|
|
|
|
final SourceSpan span;
|
|
|
|
|
2015-04-13 16:54:09 -07:00
|
|
|
PrintLoggerError(this.message, this.asset, this.span);
|
2015-04-09 17:42:14 -07:00
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return 'Message: ${Error.safeToString(message)}, '
|
|
|
|
'Asset: ${Error.safeToString(asset)}, '
|
|
|
|
'Span: ${Error.safeToString(span)}.';
|
|
|
|
}
|
|
|
|
}
|