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 log; | 6 library log; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 | 9 |
10 import 'io.dart'; | 10 import 'io.dart'; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 /// A single log entry. | 51 /// A single log entry. |
52 class Entry { | 52 class Entry { |
53 final Level level; | 53 final Level level; |
54 final List<String> lines; | 54 final List<String> lines; |
55 | 55 |
56 Entry(this.level, this.lines); | 56 Entry(this.level, this.lines); |
57 } | 57 } |
58 | 58 |
59 /// Logs [message] at [Level.ERROR]. | 59 /// Logs [message] at [Level.ERROR]. |
60 void error(message) => write(Level.ERROR, message); | 60 void error(message, [error]) { |
| 61 if (error != null) { |
| 62 message = "$message: $error"; |
| 63 var trace = getAttachedStackTrace(error); |
| 64 if (trace != null) { |
| 65 message = "$message\nStackTrace: $trace"; |
| 66 } |
| 67 } |
| 68 write(Level.ERROR, message); |
| 69 } |
61 | 70 |
62 /// Logs [message] at [Level.WARNING]. | 71 /// Logs [message] at [Level.WARNING]. |
63 void warning(message) => write(Level.WARNING, message); | 72 void warning(message) => write(Level.WARNING, message); |
64 | 73 |
65 /// Logs [message] at [Level.MESSAGE]. | 74 /// Logs [message] at [Level.MESSAGE]. |
66 void message(message) => write(Level.MESSAGE, message); | 75 void message(message) => write(Level.MESSAGE, message); |
67 | 76 |
68 /// Logs [message] at [Level.IO]. | 77 /// Logs [message] at [Level.IO]. |
69 void io(message) => write(Level.IO, message); | 78 void io(message) => write(Level.IO, message); |
70 | 79 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 sink.add(' | '.codeUnits); | 230 sink.add(' | '.codeUnits); |
222 } | 231 } |
223 } | 232 } |
224 | 233 |
225 sink.add(line.codeUnits); | 234 sink.add(line.codeUnits); |
226 sink.add('\n'.codeUnits); | 235 sink.add('\n'.codeUnits); |
227 | 236 |
228 firstLine = false; | 237 firstLine = false; |
229 } | 238 } |
230 } | 239 } |
OLD | NEW |