refactor(dart/transform): Minor logging changes

Enable easier testing by providing a null log implementation and a way
to use it.
This commit is contained in:
Tim Blasi 2015-03-18 11:03:41 -07:00 committed by Misko Hevery
parent 5d479fa0ae
commit c735644c57
2 changed files with 28 additions and 0 deletions

View File

@ -10,6 +10,11 @@ void init(Transform t) {
_logger = new BuildLogger(t); _logger = new BuildLogger(t);
} }
/// Sets [logger] directly. Used for testing - in general use [init].
void setLogger(BuildLogger logger) {
_logger = logger;
}
/// The logger the transformer should use for messaging. /// The logger the transformer should use for messaging.
BuildLogger get logger { BuildLogger get logger {
if (_logger == null) { if (_logger == null) {

View File

@ -0,0 +1,23 @@
library angular2.test.transform.common.logger;
import 'package:code_transformers/messages/build_logger.dart';
class NullLogger implements BuildLogger {
const NullLogger();
void info(String message, {AssetId asset, SourceSpan span}) {}
void fine(String message, {AssetId asset, SourceSpan span}) {}
void warning(String message, {AssetId asset, SourceSpan span}) {}
void error(String message, {AssetId asset, SourceSpan span}) {
throw new NullLoggerError(message, asset, span);
}
Future writeOutput() => null;
Future addLogFilesFromAsset(AssetId id, [int nextNumber = 1]) => null;
}
class NullLoggerError extends Error {
final String message;
final AssetId asset;
final SourceSpan span;
NullLoggerError(message, asset, span);
}