| 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 utils; | 5 library utils; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:utf' as utf; | 9 import 'dart:utf' as utf; |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 msg += ": $error"; | 33 msg += ": $error"; |
| 34 // TODO(floitsch): once the dart-executable that is bundled | 34 // TODO(floitsch): once the dart-executable that is bundled |
| 35 // with the Dart sources is updated, uncomment the following | 35 // with the Dart sources is updated, uncomment the following |
| 36 // lines. | 36 // lines. |
| 37 // var trace = getAttachedStackTrace(error); | 37 // var trace = getAttachedStackTrace(error); |
| 38 // if (trace != null) msg += "\nStackTrace: $trace"; | 38 // if (trace != null) msg += "\nStackTrace: $trace"; |
| 39 return msg; | 39 return msg; |
| 40 } | 40 } |
| 41 static void info(String msg, [error]) { | 41 static void info(String msg, [error]) { |
| 42 msg = _formatErrorMessage(msg, error); | 42 msg = _formatErrorMessage(msg, error); |
| 43 _print("Info: $msg"); | 43 _print("$_datetime Info: $msg"); |
| 44 } | 44 } |
| 45 | 45 |
| 46 static void warning(String msg, [error]) { | 46 static void warning(String msg, [error]) { |
| 47 msg = _formatErrorMessage(msg, error); | 47 msg = _formatErrorMessage(msg, error); |
| 48 _print("Warning: $msg"); | 48 _print("$_datetime Warning: $msg"); |
| 49 } | 49 } |
| 50 | 50 |
| 51 static void error(String msg, [error]) { | 51 static void error(String msg, [error]) { |
| 52 msg = _formatErrorMessage(msg, error); | 52 msg = _formatErrorMessage(msg, error); |
| 53 _print("Error: $msg"); | 53 _print("$_datetime Error: $msg"); |
| 54 } | 54 } |
| 55 | 55 |
| 56 static void _print(String msg) { | 56 static void _print(String msg) { |
| 57 if (_sink != null) { | 57 if (_sink != null) { |
| 58 _sink.writeln(msg); | 58 _sink.writeln(msg); |
| 59 } else { | 59 } else { |
| 60 print(msg); | 60 print(msg); |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 |
| 64 static String get _datetime => "${new DateTime.now()}"; |
| 63 } | 65 } |
| 64 | 66 |
| 65 List<int> encodeUtf8(String string) { | 67 List<int> encodeUtf8(String string) { |
| 66 return utf.encodeUtf8(string); | 68 return utf.encodeUtf8(string); |
| 67 } | 69 } |
| 68 | 70 |
| 69 // TODO(kustermann,ricow): As soon we have a debug log we should log | 71 // TODO(kustermann,ricow): As soon we have a debug log we should log |
| 70 // invalid utf8-encoded input to the log. | 72 // invalid utf8-encoded input to the log. |
| 71 // Currently invalid bytes will be replaced by a replacement character. | 73 // Currently invalid bytes will be replaced by a replacement character. |
| 72 String decodeUtf8(List<int> bytes) { | 74 String decodeUtf8(List<int> bytes) { |
| 73 return utf.decodeUtf8(bytes); | 75 return utf.decodeUtf8(bytes); |
| 74 } | 76 } |
| 75 | 77 |
| OLD | NEW |