| 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.barback_logger; | |
| 6 | |
| 7 import 'package:source_maps/span.dart'; | |
| 8 | |
| 9 import 'asset_id.dart'; | |
| 10 import 'errors.dart'; | |
| 11 | |
| 12 /// Object used to report warnings and errors encountered while running a | |
| 13 /// transformer. | |
| 14 class BarbackLogger { | |
| 15 /// Logs [entry]. | |
| 16 void logEntry(LogEntry entry) { | |
| 17 var buffer = new StringBuffer(); | |
| 18 buffer.write("[${entry.level} ${entry.transform}] "); | |
| 19 | |
| 20 var message = entry.message; | |
| 21 if (entry.span == null) { | |
| 22 buffer.write(entry.span.getLocationMessage(entry.message)); | |
| 23 } else { | |
| 24 buffer.write(message); | |
| 25 } | |
| 26 | |
| 27 print(buffer); | |
| 28 } | |
| 29 } | |
| 30 | |
| 31 /// The severity of a logged message. | |
| 32 class LogLevel { | |
| 33 static const INFO = const LogLevel("Info"); | |
| 34 static const WARNING = const LogLevel("Warning"); | |
| 35 static const ERROR = const LogLevel("Error"); | |
| 36 | |
| 37 final String name; | |
| 38 const LogLevel(this.name); | |
| 39 | |
| 40 String toString() => name; | |
| 41 } | |
| 42 | |
| 43 /// One message logged during a transform. | |
| 44 class LogEntry { | |
| 45 /// The transform that logged the message. | |
| 46 final TransformInfo transform; | |
| 47 | |
| 48 /// The asset that the message is associated with. | |
| 49 final AssetId asset; | |
| 50 | |
| 51 final LogLevel level; | |
| 52 final String message; | |
| 53 | |
| 54 /// The location that the message pertains to or null if not associated with | |
| 55 /// a source [Span]. | |
| 56 final Span span; | |
| 57 | |
| 58 LogEntry(this.transform, this.asset, this.level, this.message, this.span); | |
| 59 } | |
| OLD | NEW |