OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library barback.transform_logger; |
| 6 |
| 7 import 'package:source_maps/span.dart'; |
| 8 |
| 9 /// Object used to report warnings and errors encountered while running a |
| 10 /// transformer. |
| 11 class TransformLogger { |
| 12 |
| 13 bool _shouldPrint; |
| 14 |
| 15 TransformLogger(this._shouldPrint); |
| 16 |
| 17 /// Logs a warning message. |
| 18 /// |
| 19 /// If present, [span] indicates the location in the input asset that caused |
| 20 /// the warning. |
| 21 void warning(String message, [Span span]) { |
| 22 _printMessage('warning', message, span); |
| 23 } |
| 24 |
| 25 /// Logs an error message. |
| 26 /// |
| 27 /// If present, [span] indicates the location in the input asset that caused |
| 28 /// the error. |
| 29 // TODO(sigmund,nweiz): clarify when an error should be logged or thrown. |
| 30 void error(String message, [Span span]) { |
| 31 _printMessage('error', message, span); |
| 32 } |
| 33 |
| 34 // TODO(sigmund,rnystrom): do something better than printing. |
| 35 _printMessage(String prefix, String message, Span span) { |
| 36 if (!_shouldPrint) return; |
| 37 print(span == null ? '$prefix $message' |
| 38 : '$prefix ${span.getLocationMessage(message)}'); |
| 39 } |
| 40 } |
OLD | NEW |