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

Side by Side Diff: pkg/logging/lib/logging.dart

Issue 17467008: add logging support for exceptions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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
« no previous file with comments | « no previous file | pkg/logging/test/logging_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /** 5 /**
6 * Provides APIs for debugging and error logging. This library introduces 6 * Provides APIs for debugging and error logging. This library introduces
7 * abstractions similar to those used in other languages, such as the Closure JS 7 * abstractions similar to those used in other languages, such as the Closure JS
8 * Logger and java.util.logging.Logger. 8 * Logger and java.util.logging.Logger.
9 * 9 *
10 * ## Installing ## 10 * ## Installing ##
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 /** Whether a message for [value]'s level is loggable in this logger. */ 146 /** Whether a message for [value]'s level is loggable in this logger. */
147 bool isLoggable(Level value) => (value >= level); 147 bool isLoggable(Level value) => (value >= level);
148 148
149 /** 149 /**
150 * Adds a log record for a [message] at a particular [logLevel] if 150 * Adds a log record for a [message] at a particular [logLevel] if
151 * `isLoggable(logLevel)` is true. Use this method to create log entries for 151 * `isLoggable(logLevel)` is true. Use this method to create log entries for
152 * user-defined levels. To record a message at a predefined level (e.g. 152 * user-defined levels. To record a message at a predefined level (e.g.
153 * [Level.INFO], [Level.WARNING], etc) you can use their specialized methods 153 * [Level.INFO], [Level.WARNING], etc) you can use their specialized methods
154 * instead (e.g. [info], [warning], etc). 154 * instead (e.g. [info], [warning], etc).
155 */ 155 */
156 // TODO(sigmund): add support for logging exceptions. 156 void log(Level logLevel, String message, [exception]) {
157 void log(Level logLevel, String message) {
158 if (isLoggable(logLevel)) { 157 if (isLoggable(logLevel)) {
159 var record = new LogRecord(logLevel, message, fullName); 158 var record = new LogRecord(logLevel, message, fullName, exception);
160 if (hierarchicalLoggingEnabled) { 159 if (hierarchicalLoggingEnabled) {
161 var target = this; 160 var target = this;
162 while (target != null) { 161 while (target != null) {
163 target._publish(record); 162 target._publish(record);
164 target = target.parent; 163 target = target.parent;
165 } 164 }
166 } else { 165 } else {
167 root._publish(record); 166 root._publish(record);
168 } 167 }
169 } 168 }
170 } 169 }
171 170
172 /** Log message at level [Level.FINEST]. */ 171 /** Log message at level [Level.FINEST]. */
173 void finest(String message) => log(Level.FINEST, message); 172 void finest(String message, [exception]) =>
173 log(Level.FINEST, message, exception);
174 174
175 /** Log message at level [Level.FINER]. */ 175 /** Log message at level [Level.FINER]. */
176 void finer(String message) => log(Level.FINER, message); 176 void finer(String message, [exception]) =>
177 log(Level.FINER, message, exception);
177 178
178 /** Log message at level [Level.FINE]. */ 179 /** Log message at level [Level.FINE]. */
179 void fine(String message) => log(Level.FINE, message); 180 void fine(String message, [exception]) =>
181 log(Level.FINE, message, exception);
180 182
181 /** Log message at level [Level.CONFIG]. */ 183 /** Log message at level [Level.CONFIG]. */
182 void config(String message) => log(Level.CONFIG, message); 184 void config(String message, [exception]) =>
185 log(Level.CONFIG, message, exception);
183 186
184 /** Log message at level [Level.INFO]. */ 187 /** Log message at level [Level.INFO]. */
185 void info(String message) => log(Level.INFO, message); 188 void info(String message, [exception]) =>
189 log(Level.INFO, message, exception);
186 190
187 /** Log message at level [Level.WARNING]. */ 191 /** Log message at level [Level.WARNING]. */
188 void warning(String message) => log(Level.WARNING, message); 192 void warning(String message, [exception]) =>
193 log(Level.WARNING, message, exception);
189 194
190 /** Log message at level [Level.SEVERE]. */ 195 /** Log message at level [Level.SEVERE]. */
191 void severe(String message) => log(Level.SEVERE, message); 196 void severe(String message, [exception]) =>
197 log(Level.SEVERE, message, exception);
192 198
193 /** Log message at level [Level.SHOUT]. */ 199 /** Log message at level [Level.SHOUT]. */
194 void shout(String message) => log(Level.SHOUT, message); 200 void shout(String message, [exception]) =>
201 log(Level.SHOUT, message, exception);
195 202
196 Stream<LogRecord> _getStream() { 203 Stream<LogRecord> _getStream() {
197 if (hierarchicalLoggingEnabled || parent == null) { 204 if (hierarchicalLoggingEnabled || parent == null) {
198 if (_controller == null) { 205 if (_controller == null) {
199 _controller = new StreamController<LogRecord>(sync: true); 206 _controller = new StreamController<LogRecord>(sync: true);
200 _stream = _controller.stream.asBroadcastStream(); 207 _stream = _controller.stream.asBroadcastStream();
201 } 208 }
202 return _stream; 209 return _stream;
203 } else { 210 } else {
204 return root._getStream(); 211 return root._getStream();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 308
302 /** Time when this record was created. */ 309 /** Time when this record was created. */
303 final DateTime time; 310 final DateTime time;
304 311
305 /** Unique sequence number greater than all log records created before it. */ 312 /** Unique sequence number greater than all log records created before it. */
306 final int sequenceNumber; 313 final int sequenceNumber;
307 314
308 static int _nextNumber = 0; 315 static int _nextNumber = 0;
309 316
310 /** Associated exception (if any) when recording errors messages. */ 317 /** Associated exception (if any) when recording errors messages. */
311 Exception exception; 318 var exception;
312 319
313 /** Associated exception message (if any) when recording errors messages. */ 320 LogRecord(this.level, this.message, this.loggerName, [this.exception])
314 String exceptionText; 321 : time = new DateTime.now(),
315 322 sequenceNumber = LogRecord._nextNumber++;
316 LogRecord(
317 this.level, this.message, this.loggerName,
318 [time, this.exception, this.exceptionText]) :
319 this.time = (time == null) ? new DateTime.now() : time,
320 this.sequenceNumber = LogRecord._nextNumber++;
321 } 323 }
OLDNEW
« no previous file with comments | « no previous file | pkg/logging/test/logging_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698