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:
parent
5d479fa0ae
commit
c735644c57
|
@ -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) {
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
Loading…
Reference in New Issue