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 18 matching lines...) Expand all Loading... |
29 /// though possibly in a degraded fashion. | 29 /// though possibly in a degraded fashion. |
30 static const WARNING = const Level._("WARN"); | 30 static const WARNING = const Level._("WARN"); |
31 | 31 |
32 /// A message intended specifically to be shown to the user. | 32 /// A message intended specifically to be shown to the user. |
33 static const MESSAGE = const Level._("MSG "); | 33 static const MESSAGE = const Level._("MSG "); |
34 | 34 |
35 /// Some interaction with the external world occurred, such as a network | 35 /// Some interaction with the external world occurred, such as a network |
36 /// operation, process spawning, or file IO. | 36 /// operation, process spawning, or file IO. |
37 static const IO = const Level._("IO "); | 37 static const IO = const Level._("IO "); |
38 | 38 |
| 39 /// Incremental output during pub's version constraint solver. |
| 40 static const SOLVER = const Level._("SLVR"); |
| 41 |
39 /// Fine-grained and verbose additional information. Can be used to provide | 42 /// Fine-grained and verbose additional information. Can be used to provide |
40 /// program state context for other logs (such as what pub was doing when an | 43 /// program state context for other logs (such as what pub was doing when an |
41 /// IO operation occurred) or just more detail for an operation. | 44 /// IO operation occurred) or just more detail for an operation. |
42 static const FINE = const Level._("FINE"); | 45 static const FINE = const Level._("FINE"); |
43 | 46 |
44 const Level._(this.name); | 47 const Level._(this.name); |
45 final String name; | 48 final String name; |
46 | 49 |
47 String toString() => name; | 50 String toString() => name; |
48 int get hashCode => name.hashCode; | 51 int get hashCode => name.hashCode; |
(...skipping 12 matching lines...) Expand all Loading... |
61 | 64 |
62 /// Logs [message] at [Level.WARNING]. | 65 /// Logs [message] at [Level.WARNING]. |
63 void warning(message) => write(Level.WARNING, message); | 66 void warning(message) => write(Level.WARNING, message); |
64 | 67 |
65 /// Logs [message] at [Level.MESSAGE]. | 68 /// Logs [message] at [Level.MESSAGE]. |
66 void message(message) => write(Level.MESSAGE, message); | 69 void message(message) => write(Level.MESSAGE, message); |
67 | 70 |
68 /// Logs [message] at [Level.IO]. | 71 /// Logs [message] at [Level.IO]. |
69 void io(message) => write(Level.IO, message); | 72 void io(message) => write(Level.IO, message); |
70 | 73 |
| 74 /// Logs [message] at [Level.SOLVER]. |
| 75 void solver(message) => write(Level.SOLVER, message); |
| 76 |
71 /// Logs [message] at [Level.FINE]. | 77 /// Logs [message] at [Level.FINE]. |
72 void fine(message) => write(Level.FINE, message); | 78 void fine(message) => write(Level.FINE, message); |
73 | 79 |
74 /// Logs [message] at [level]. | 80 /// Logs [message] at [level]. |
75 void write(Level level, message) { | 81 void write(Level level, message) { |
76 if (_loggers.isEmpty) showNormal(); | 82 if (_loggers.isEmpty) showNormal(); |
77 | 83 |
78 var lines = splitLines(message.toString()); | 84 var lines = splitLines(message.toString()); |
79 var entry = new Entry(level, lines); | 85 var entry = new Entry(level, lines); |
80 | 86 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 } | 167 } |
162 stderrSink.add('---- End log transcript ----\n'.codeUnits); | 168 stderrSink.add('---- End log transcript ----\n'.codeUnits); |
163 } | 169 } |
164 | 170 |
165 /// Sets the verbosity to "normal", which shows errors, warnings, and messages. | 171 /// Sets the verbosity to "normal", which shows errors, warnings, and messages. |
166 void showNormal() { | 172 void showNormal() { |
167 _loggers[Level.ERROR] = _logToStderr; | 173 _loggers[Level.ERROR] = _logToStderr; |
168 _loggers[Level.WARNING] = _logToStderr; | 174 _loggers[Level.WARNING] = _logToStderr; |
169 _loggers[Level.MESSAGE] = _logToStdout; | 175 _loggers[Level.MESSAGE] = _logToStdout; |
170 _loggers[Level.IO] = null; | 176 _loggers[Level.IO] = null; |
| 177 _loggers[Level.SOLVER] = null; |
171 _loggers[Level.FINE] = null; | 178 _loggers[Level.FINE] = null; |
172 } | 179 } |
173 | 180 |
174 /// Sets the verbosity to "io", which shows errors, warnings, messages, and IO | 181 /// Sets the verbosity to "io", which shows errors, warnings, messages, and IO |
175 /// event logs. | 182 /// event logs. |
176 void showIO() { | 183 void showIO() { |
177 _loggers[Level.ERROR] = _logToStderrWithLabel; | 184 _loggers[Level.ERROR] = _logToStderrWithLabel; |
178 _loggers[Level.WARNING] = _logToStderrWithLabel; | 185 _loggers[Level.WARNING] = _logToStderrWithLabel; |
179 _loggers[Level.MESSAGE] = _logToStdoutWithLabel; | 186 _loggers[Level.MESSAGE] = _logToStdoutWithLabel; |
180 _loggers[Level.IO] = _logToStderrWithLabel; | 187 _loggers[Level.IO] = _logToStderrWithLabel; |
| 188 _loggers[Level.SOLVER] = null; |
181 _loggers[Level.FINE] = null; | 189 _loggers[Level.FINE] = null; |
182 } | 190 } |
183 | 191 |
| 192 /// Sets the verbosity to "solver", which shows errors, warnings, messages, and |
| 193 /// solver logs. |
| 194 void showSolver() { |
| 195 _loggers[Level.ERROR] = _logToStderr; |
| 196 _loggers[Level.WARNING] = _logToStderr; |
| 197 _loggers[Level.MESSAGE] = _logToStdout; |
| 198 _loggers[Level.IO] = null; |
| 199 _loggers[Level.SOLVER] = _logToStdout; |
| 200 _loggers[Level.FINE] = null; |
| 201 } |
| 202 |
184 /// Sets the verbosity to "all", which logs ALL the things. | 203 /// Sets the verbosity to "all", which logs ALL the things. |
185 void showAll() { | 204 void showAll() { |
186 _loggers[Level.ERROR] = _logToStderrWithLabel; | 205 _loggers[Level.ERROR] = _logToStderrWithLabel; |
187 _loggers[Level.WARNING] = _logToStderrWithLabel; | 206 _loggers[Level.WARNING] = _logToStderrWithLabel; |
188 _loggers[Level.MESSAGE] = _logToStdoutWithLabel; | 207 _loggers[Level.MESSAGE] = _logToStdoutWithLabel; |
189 _loggers[Level.IO] = _logToStderrWithLabel; | 208 _loggers[Level.IO] = _logToStderrWithLabel; |
| 209 _loggers[Level.SOLVER] = _logToStderrWithLabel; |
190 _loggers[Level.FINE] = _logToStderrWithLabel; | 210 _loggers[Level.FINE] = _logToStderrWithLabel; |
191 } | 211 } |
192 | 212 |
193 /// Log function that prints the message to stdout. | 213 /// Log function that prints the message to stdout. |
194 void _logToStdout(Entry entry) { | 214 void _logToStdout(Entry entry) { |
195 _logToStream(stdoutSink, entry, showLabel: false); | 215 _logToStream(stdoutSink, entry, showLabel: false); |
196 } | 216 } |
197 | 217 |
198 /// Log function that prints the message to stdout with the level name. | 218 /// Log function that prints the message to stdout with the level name. |
199 void _logToStdoutWithLabel(Entry entry) { | 219 void _logToStdoutWithLabel(Entry entry) { |
(...skipping 21 matching lines...) Expand all Loading... |
221 sink.add(' | '.codeUnits); | 241 sink.add(' | '.codeUnits); |
222 } | 242 } |
223 } | 243 } |
224 | 244 |
225 sink.add(line.codeUnits); | 245 sink.add(line.codeUnits); |
226 sink.add('\n'.codeUnits); | 246 sink.add('\n'.codeUnits); |
227 | 247 |
228 firstLine = false; | 248 firstLine = false; |
229 } | 249 } |
230 } | 250 } |
OLD | NEW |