Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library barback.transform_logger; | 5 library barback.transform_logger; |
| 6 | 6 |
| 7 import 'package:source_maps/span.dart'; | 7 import 'package:source_maps/span.dart'; |
| 8 | 8 |
| 9 /// Object used to report warnings and errors encountered while running a | 9 /// Object used to report warnings and errors encountered while running a |
| 10 /// transformer. | 10 /// transformer. |
| 11 class TransformLogger { | 11 class TransformLogger { |
| 12 | 12 |
| 13 bool _shouldPrint; | 13 bool _shouldPrint; |
| 14 | 14 |
| 15 TransformLogger(this._shouldPrint); | 15 TransformLogger(this._shouldPrint); |
| 16 | 16 |
| 17 /// Logs an informative message. | |
| 18 /// | |
| 19 /// If present, [span] indicates the location in the input asset that caused | |
| 20 /// the warning. | |
|
nweiz
2013/09/27 22:21:17
"warning" -> "message"
Bob Nystrom
2013/09/28 00:56:11
Done.
| |
| 21 void info(String message, [Span span]) { | |
| 22 _printMessage('info', message, span); | |
| 23 } | |
| 24 | |
| 17 /// Logs a warning message. | 25 /// Logs a warning message. |
| 18 /// | 26 /// |
| 19 /// If present, [span] indicates the location in the input asset that caused | 27 /// If present, [span] indicates the location in the input asset that caused |
| 20 /// the warning. | 28 /// the warning. |
| 21 void warning(String message, [Span span]) { | 29 void warning(String message, [Span span]) { |
| 22 _printMessage('warning', message, span); | 30 _printMessage('warning', message, span); |
| 23 } | 31 } |
| 24 | 32 |
| 25 /// Logs an error message. | 33 /// Logs an error message. |
| 26 /// | 34 /// |
| 27 /// If present, [span] indicates the location in the input asset that caused | 35 /// If present, [span] indicates the location in the input asset that caused |
| 28 /// the error. | 36 /// the error. |
| 29 // TODO(sigmund,nweiz): clarify when an error should be logged or thrown. | 37 // TODO(sigmund,nweiz): clarify when an error should be logged or thrown. |
| 30 void error(String message, [Span span]) { | 38 void error(String message, [Span span]) { |
| 31 _printMessage('error', message, span); | 39 _printMessage('error', message, span); |
| 32 } | 40 } |
| 33 | 41 |
| 34 // TODO(sigmund,rnystrom): do something better than printing. | 42 // TODO(sigmund,rnystrom): do something better than printing. |
| 35 _printMessage(String prefix, String message, Span span) { | 43 _printMessage(String prefix, String message, Span span) { |
| 36 if (!_shouldPrint) return; | 44 if (!_shouldPrint) return; |
| 37 print(span == null ? '$prefix $message' | 45 print(span == null ? '$prefix $message' |
| 38 : '$prefix ${span.getLocationMessage(message)}'); | 46 : '$prefix ${span.getLocationMessage(message)}'); |
| 39 } | 47 } |
| 40 } | 48 } |
| OLD | NEW |