| 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.transformer.transform_logger; | 5 library barback.transformer.transform_logger; |
| 6 | 6 |
| 7 import 'package:source_maps/span.dart'; | 7 import 'package:source_maps/span.dart'; |
| 8 import 'package:source_span/source_span.dart'; |
| 8 | 9 |
| 9 import '../asset/asset_id.dart'; | 10 import '../asset/asset_id.dart'; |
| 10 import '../log.dart'; | 11 import '../log.dart'; |
| 12 import '../span_wrapper.dart'; |
| 11 | 13 |
| 12 typedef void LogFunction(AssetId asset, LogLevel level, String message, | 14 typedef void LogFunction(AssetId asset, LogLevel level, String message, |
| 13 Span span); | 15 Span span); |
| 14 | 16 |
| 15 /// Object used to report warnings and errors encountered while running a | 17 /// Object used to report warnings and errors encountered while running a |
| 16 /// transformer. | 18 /// transformer. |
| 17 class TransformLogger { | 19 class TransformLogger { |
| 18 final LogFunction _logFunction; | 20 final LogFunction _logFunction; |
| 19 | 21 |
| 20 TransformLogger(this._logFunction); | 22 TransformLogger(this._logFunction); |
| 21 | 23 |
| 22 /// Logs an informative message. | 24 /// Logs an informative message. |
| 23 /// | 25 /// |
| 24 /// If [asset] is provided, the log entry is associated with that asset. | 26 /// If [asset] is provided, the log entry is associated with that asset. |
| 25 /// Otherwise it's associated with the primary input of [transformer]. | 27 /// Otherwise it's associated with the primary input of [transformer]. If |
| 26 /// If [span] is provided, indicates the location in the input asset that | 28 /// present, [span] indicates the location in the input asset that caused the |
| 27 /// caused the message. | 29 /// error. It may be a [SourceSpan] or a [Span], although the former is |
| 28 void info(String message, {AssetId asset, Span span}) { | 30 /// recommended. |
| 31 void info(String message, {AssetId asset, span}) { |
| 32 if (span != null && span is SourceSpan) span = new SpanWrapper(span, false); |
| 29 _logFunction(asset, LogLevel.INFO, message, span); | 33 _logFunction(asset, LogLevel.INFO, message, span); |
| 30 } | 34 } |
| 31 | 35 |
| 32 /// Logs a message that won't be displayed unless the user is running in | 36 /// Logs a message that won't be displayed unless the user is running in |
| 33 /// verbose mode. | 37 /// verbose mode. |
| 34 /// | 38 /// |
| 35 /// If [asset] is provided, the log entry is associated with that asset. | 39 /// If [asset] is provided, the log entry is associated with that asset. |
| 36 /// Otherwise it's associated with the primary input of [transformer]. | 40 /// Otherwise it's associated with the primary input of [transformer]. If |
| 37 /// If [span] is provided, indicates the location in the input asset that | 41 /// present, [span] indicates the location in the input asset that caused the |
| 38 /// caused the message. | 42 /// error. It may be a [SourceSpan] or a [Span], although the former is |
| 39 void fine(String message, {AssetId asset, Span span}) { | 43 /// recommended. |
| 44 void fine(String message, {AssetId asset, span}) { |
| 45 if (span != null && span is SourceSpan) span = new SpanWrapper(span, false); |
| 40 _logFunction(asset, LogLevel.FINE, message, span); | 46 _logFunction(asset, LogLevel.FINE, message, span); |
| 41 } | 47 } |
| 42 | 48 |
| 43 /// Logs a warning message. | 49 /// Logs a warning message. |
| 44 /// | 50 /// |
| 45 /// If [asset] is provided, the log entry is associated with that asset. | 51 /// If [asset] is provided, the log entry is associated with that asset. |
| 46 /// Otherwise it's associated with the primary input of [transformer]. | 52 /// Otherwise it's associated with the primary input of [transformer]. If |
| 47 /// If present, [span] indicates the location in the input asset that caused | 53 /// present, [span] indicates the location in the input asset that caused the |
| 48 /// the warning. | 54 /// error. It may be a [SourceSpan] or a [Span], although the former is |
| 49 void warning(String message, {AssetId asset, Span span}) { | 55 /// recommended. |
| 56 void warning(String message, {AssetId asset, span}) { |
| 57 if (span != null && span is SourceSpan) span = new SpanWrapper(span, false); |
| 50 _logFunction(asset, LogLevel.WARNING, message, span); | 58 _logFunction(asset, LogLevel.WARNING, message, span); |
| 51 } | 59 } |
| 52 | 60 |
| 53 /// Logs an error message. | 61 /// Logs an error message. |
| 54 /// | 62 /// |
| 55 /// If [asset] is provided, the log entry is associated with that asset. | 63 /// If [asset] is provided, the log entry is associated with that asset. |
| 56 /// Otherwise it's associated with the primary input of [transformer]. | 64 /// Otherwise it's associated with the primary input of [transformer]. If |
| 57 /// If present, [span] indicates the location in the input asset that caused | 65 /// present, [span] indicates the location in the input asset that caused the |
| 58 /// the error. | 66 /// error. It may be a [SourceSpan] or a [Span], although the former is |
| 67 /// recommended. |
| 59 /// | 68 /// |
| 60 /// Logging any errors will cause Barback to consider the transformation to | 69 /// Logging any errors will cause Barback to consider the transformation to |
| 61 /// have failed, much like throwing an exception. This means that neither the | 70 /// have failed, much like throwing an exception. This means that neither the |
| 62 /// primary input nor any outputs emitted by the transformer will be passed on | 71 /// primary input nor any outputs emitted by the transformer will be passed on |
| 63 /// to the following phase, and the build will be reported as having failed. | 72 /// to the following phase, and the build will be reported as having failed. |
| 64 /// | 73 /// |
| 65 /// Unlike throwing an exception, this doesn't cause a transformer to stop | 74 /// Unlike throwing an exception, this doesn't cause a transformer to stop |
| 66 /// running. This makes it useful in cases where a single input may have | 75 /// running. This makes it useful in cases where a single input may have |
| 67 /// multiple errors that the user wants to know about. | 76 /// multiple errors that the user wants to know about. |
| 68 void error(String message, {AssetId asset, Span span}) { | 77 void error(String message, {AssetId asset, span}) { |
| 78 if (span != null && span is SourceSpan) span = new SpanWrapper(span, false); |
| 69 _logFunction(asset, LogLevel.ERROR, message, span); | 79 _logFunction(asset, LogLevel.ERROR, message, span); |
| 70 } | 80 } |
| 71 } | 81 } |
| OLD | NEW |