| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /// Message logging. | 5 /// Message logging. |
| 6 library pub.log; | 6 library pub.log; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 void error(error, [stackTrace]) { | 521 void error(error, [stackTrace]) { |
| 522 var errorJson = {"error": error.toString()}; | 522 var errorJson = {"error": error.toString()}; |
| 523 | 523 |
| 524 if (stackTrace == null && error is Error) stackTrace = error.stackTrace; | 524 if (stackTrace == null && error is Error) stackTrace = error.stackTrace; |
| 525 if (stackTrace != null) { | 525 if (stackTrace != null) { |
| 526 errorJson["stackTrace"] = new Chain.forTrace(stackTrace).toString(); | 526 errorJson["stackTrace"] = new Chain.forTrace(stackTrace).toString(); |
| 527 } | 527 } |
| 528 | 528 |
| 529 // If the error came from a file, include the path. | 529 // If the error came from a file, include the path. |
| 530 if (error is SourceSpanException && error.span.sourceUrl != null) { | 530 if (error is SourceSpanException && error.span.sourceUrl != null) { |
| 531 errorJson["path"] = p.fromUri(error.span.sourceUrl); | 531 // Normalize paths and make them absolute for backwards compatibility with |
| 532 // the protocol used by the analyzer. |
| 533 errorJson["path"] = p.normalize(p.absolute( |
| 534 p.fromUri(error.span.sourceUrl))); |
| 532 } | 535 } |
| 533 | 536 |
| 534 if (error is FileException) { | 537 if (error is FileException) { |
| 535 errorJson["path"] = error.path; | 538 errorJson["path"] = p.normalize(p.absolute(error.path)); |
| 536 } | 539 } |
| 537 | 540 |
| 538 this.message(errorJson); | 541 this.message(errorJson); |
| 539 } | 542 } |
| 540 | 543 |
| 541 /// Encodes [message] to JSON and prints it if JSON output is enabled. | 544 /// Encodes [message] to JSON and prints it if JSON output is enabled. |
| 542 void message(message) { | 545 void message(message) { |
| 543 if (!enabled) return; | 546 if (!enabled) return; |
| 544 | 547 |
| 545 print(JSON.encode(message)); | 548 print(JSON.encode(message)); |
| 546 } | 549 } |
| 547 } | 550 } |
| OLD | NEW |