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

Side by Side Diff: utils/pub/log.dart

Issue 13095015: Use backtracking when solving dependency constraints. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Clean up some test code. Created 7 years, 8 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) 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
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;
49 } 52 }
50 53
51 /// A single log entry. 54 /// A single log entry.
52 class Entry { 55 class Entry {
53 final Level level; 56 final Level level;
54 final List<String> lines; 57 final List<String> lines;
55 58
56 Entry(this.level, this.lines); 59 Entry(this.level, this.lines);
57 } 60 }
58 61
62 /// Returns `true` if [level] is being recorded in some way.
63 bool isEnabled(Level level) => _loggers != null && _loggers[level] != null;
64
59 /// Logs [message] at [Level.ERROR]. 65 /// Logs [message] at [Level.ERROR].
60 void error(message) => write(Level.ERROR, message); 66 void error(message) => write(Level.ERROR, message);
61 67
62 /// Logs [message] at [Level.WARNING]. 68 /// Logs [message] at [Level.WARNING].
63 void warning(message) => write(Level.WARNING, message); 69 void warning(message) => write(Level.WARNING, message);
64 70
65 /// Logs [message] at [Level.MESSAGE]. 71 /// Logs [message] at [Level.MESSAGE].
66 void message(message) => write(Level.MESSAGE, message); 72 void message(message) => write(Level.MESSAGE, message);
67 73
68 /// Logs [message] at [Level.IO]. 74 /// Logs [message] at [Level.IO].
69 void io(message) => write(Level.IO, message); 75 void io(message) => write(Level.IO, message);
70 76
77 /// Logs [message] at [Level.SOLVER].
78 void solver(message) => write(Level.SOLVER, message);
79
71 /// Logs [message] at [Level.FINE]. 80 /// Logs [message] at [Level.FINE].
72 void fine(message) => write(Level.FINE, message); 81 void fine(message) => write(Level.FINE, message);
73 82
74 /// Logs [message] at [level]. 83 /// Logs [message] at [level].
75 void write(Level level, message) { 84 void write(Level level, message) {
76 if (_loggers.isEmpty) showNormal(); 85 if (_loggers.isEmpty) showNormal();
77 86
78 var lines = splitLines(message.toString()); 87 var lines = splitLines(message.toString());
79 var entry = new Entry(level, lines); 88 var entry = new Entry(level, lines);
80 89
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 170 }
162 stderrSink.add('---- End log transcript ----\n'.codeUnits); 171 stderrSink.add('---- End log transcript ----\n'.codeUnits);
163 } 172 }
164 173
165 /// Sets the verbosity to "normal", which shows errors, warnings, and messages. 174 /// Sets the verbosity to "normal", which shows errors, warnings, and messages.
166 void showNormal() { 175 void showNormal() {
167 _loggers[Level.ERROR] = _logToStderr; 176 _loggers[Level.ERROR] = _logToStderr;
168 _loggers[Level.WARNING] = _logToStderr; 177 _loggers[Level.WARNING] = _logToStderr;
169 _loggers[Level.MESSAGE] = _logToStdout; 178 _loggers[Level.MESSAGE] = _logToStdout;
170 _loggers[Level.IO] = null; 179 _loggers[Level.IO] = null;
180 _loggers[Level.SOLVER] = null;
171 _loggers[Level.FINE] = null; 181 _loggers[Level.FINE] = null;
172 } 182 }
173 183
174 /// Sets the verbosity to "io", which shows errors, warnings, messages, and IO 184 /// Sets the verbosity to "io", which shows errors, warnings, messages, and IO
175 /// event logs. 185 /// event logs.
176 void showIO() { 186 void showIO() {
177 _loggers[Level.ERROR] = _logToStderrWithLabel; 187 _loggers[Level.ERROR] = _logToStderrWithLabel;
178 _loggers[Level.WARNING] = _logToStderrWithLabel; 188 _loggers[Level.WARNING] = _logToStderrWithLabel;
179 _loggers[Level.MESSAGE] = _logToStdoutWithLabel; 189 _loggers[Level.MESSAGE] = _logToStdoutWithLabel;
180 _loggers[Level.IO] = _logToStderrWithLabel; 190 _loggers[Level.IO] = _logToStderrWithLabel;
191 _loggers[Level.SOLVER] = null;
181 _loggers[Level.FINE] = null; 192 _loggers[Level.FINE] = null;
182 } 193 }
183 194
195 /// Sets the verbosity to "solver", which shows errors, warnings, messages, and
196 /// solver logs.
197 void showSolver() {
198 _loggers[Level.ERROR] = _logToStderr;
199 _loggers[Level.WARNING] = _logToStderr;
200 _loggers[Level.MESSAGE] = _logToStdout;
201 _loggers[Level.IO] = null;
202 _loggers[Level.SOLVER] = _logToStdout;
203 _loggers[Level.FINE] = null;
204 }
205
184 /// Sets the verbosity to "all", which logs ALL the things. 206 /// Sets the verbosity to "all", which logs ALL the things.
185 void showAll() { 207 void showAll() {
186 _loggers[Level.ERROR] = _logToStderrWithLabel; 208 _loggers[Level.ERROR] = _logToStderrWithLabel;
187 _loggers[Level.WARNING] = _logToStderrWithLabel; 209 _loggers[Level.WARNING] = _logToStderrWithLabel;
188 _loggers[Level.MESSAGE] = _logToStdoutWithLabel; 210 _loggers[Level.MESSAGE] = _logToStdoutWithLabel;
189 _loggers[Level.IO] = _logToStderrWithLabel; 211 _loggers[Level.IO] = _logToStderrWithLabel;
212 _loggers[Level.SOLVER] = _logToStderrWithLabel;
190 _loggers[Level.FINE] = _logToStderrWithLabel; 213 _loggers[Level.FINE] = _logToStderrWithLabel;
191 } 214 }
192 215
193 /// Log function that prints the message to stdout. 216 /// Log function that prints the message to stdout.
194 void _logToStdout(Entry entry) { 217 void _logToStdout(Entry entry) {
195 _logToStream(stdoutSink, entry, showLabel: false); 218 _logToStream(stdoutSink, entry, showLabel: false);
196 } 219 }
197 220
198 /// Log function that prints the message to stdout with the level name. 221 /// Log function that prints the message to stdout with the level name.
199 void _logToStdoutWithLabel(Entry entry) { 222 void _logToStdoutWithLabel(Entry entry) {
(...skipping 21 matching lines...) Expand all
221 sink.add(' | '.codeUnits); 244 sink.add(' | '.codeUnits);
222 } 245 }
223 } 246 }
224 247
225 sink.add(line.codeUnits); 248 sink.add(line.codeUnits);
226 sink.add('\n'.codeUnits); 249 sink.add('\n'.codeUnits);
227 250
228 firstLine = false; 251 firstLine = false;
229 } 252 }
230 } 253 }
OLDNEW
« no previous file with comments | « utils/pub/entrypoint.dart ('k') | utils/pub/package.dart » ('j') | utils/pub/package.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698