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 import 'asset_id.dart'; | |
10 import 'barback_logger.dart'; | |
11 import 'transform.dart'; | |
12 | |
9 /// Object used to report warnings and errors encountered while running a | 13 /// Object used to report warnings and errors encountered while running a |
10 /// transformer. | 14 /// transformer. |
11 class TransformLogger { | 15 class TransformLogger { |
16 final LogFunction _logFunction; | |
12 | 17 |
13 bool _shouldPrint; | 18 TransformLogger(this._logFunction); |
14 | |
15 TransformLogger(this._shouldPrint); | |
16 | 19 |
17 /// Logs an informative message. | 20 /// Logs an informative message. |
18 /// | 21 /// |
19 /// If present, [span] indicates the location in the input asset that caused | 22 /// If [asset] is provided, the log entry is associated with that asset, |
nweiz
2013/10/16 19:41:27
", otherwise" -> ". Otherwise"
also below
Bob Nystrom
2013/10/28 23:45:56
Done.
| |
20 /// the message. | 23 /// otherwise it's associated with the primary input of [transformer]. |
21 void info(String message, [Span span]) { | 24 /// If [span] is provided, indicates the location in the input asset that |
22 _printMessage('info', message, span); | 25 /// caused the message. |
26 void info(String message, {AssetId asset, Span span}) { | |
27 _logFunction(asset, LogLevel.INFO, message, span); | |
23 } | 28 } |
24 | 29 |
25 /// Logs a warning message. | 30 /// Logs a warning message. |
26 /// | 31 /// |
32 /// If [asset] is provided, the log entry is associated with that asset, | |
33 /// otherwise it's associated with the primary input of [transformer]. | |
27 /// If present, [span] indicates the location in the input asset that caused | 34 /// If present, [span] indicates the location in the input asset that caused |
28 /// the warning. | 35 /// the warning. |
29 void warning(String message, [Span span]) { | 36 void warning(String message, {AssetId asset, Span span}) { |
30 _printMessage('warning', message, span); | 37 _logFunction(asset, LogLevel.WARNING, message, span); |
31 } | 38 } |
32 | 39 |
33 /// Logs an error message. | 40 /// Logs an error message. |
34 /// | 41 /// |
42 /// If [asset] is provided, the log entry is associated with that asset, | |
43 /// otherwise it's associated with the primary input of [transformer]. | |
35 /// If present, [span] indicates the location in the input asset that caused | 44 /// If present, [span] indicates the location in the input asset that caused |
36 /// the error. | 45 /// the error. |
37 // TODO(sigmund,nweiz): clarify when an error should be logged or thrown. | 46 // TODO(sigmund,nweiz): clarify when an error should be logged or thrown. |
38 void error(String message, [Span span]) { | 47 void error(String message, {AssetId asset, Span span}) { |
39 _printMessage('error', message, span); | 48 _logFunction(asset, LogLevel.ERROR, message, span); |
40 } | |
41 | |
42 // TODO(sigmund,rnystrom): do something better than printing. | |
43 _printMessage(String prefix, String message, Span span) { | |
44 if (!_shouldPrint) return; | |
45 print(span == null ? '$prefix: $message' | |
46 : '$prefix ${span.getLocationMessage(message)}'); | |
47 } | 49 } |
48 } | 50 } |
OLD | NEW |