Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: tools/testing/dart/utils.dart

Issue 11962042: Added DebugLogger to testing scripts. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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:utf' as utf; 8 import 'dart:utf' as utf;
8 9
10 class DebugLogger {
11 static OutputStream _stream;
12
13 /**
14 * If [path] was null, the DebugLogger will write messages to stdout.
15 */
16 static init(Path path) {
17 if (path != null) {
18 _stream = new File.fromPath(path).openOutputStream();
19 }
20 }
21
22 static void close() {
23 if (_stream != null) {
24 _stream.close();
25 _stream = null;
26 }
27 }
28
29 static void info(String msg) {
30 _print("Info: $msg");
31 }
32
33 static void warning(String msg) {
34 _print("Warning: $msg");
35 }
36
37 static void error(String msg) {
38 _print("Error: $msg");
39 }
40
41 static void _print(String msg) {
42 if (_stream != null) {
43 _stream.write(encodeUtf8(msg));
44 _stream.write([0x0a]);
45 } else {
46 print(msg);
47 }
48 }
49 }
9 50
10 List<int> encodeUtf8(String string) { 51 List<int> encodeUtf8(String string) {
11 return utf.encodeUtf8(string); 52 return utf.encodeUtf8(string);
12 } 53 }
13 54
14 // TODO(kustermann,ricow): As soon we have a debug log we should log 55 // TODO(kustermann,ricow): As soon we have a debug log we should log
15 // invalid utf8-encoded input to the log. 56 // invalid utf8-encoded input to the log.
16 // Currently invalid bytes will be replaced by a replacement character. 57 // Currently invalid bytes will be replaced by a replacement character.
17 String decodeUtf8(List<int> bytes) { 58 String decodeUtf8(List<int> bytes) {
18 return utf.decodeUtf8(bytes); 59 return utf.decodeUtf8(bytes);
19 } 60 }
20 61
OLDNEW
« tools/testing/dart/test_progress.dart ('K') | « tools/testing/dart/test_suite.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698