Chromium Code Reviews| 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 /** | 5 /** |
| 6 */ | 6 */ |
| 7 library logging; | 7 library logging; |
| 8 | 8 |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import 'dart:collection'; | 10 import 'dart:collection'; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 /** | 130 /** |
| 131 * Adds a log record for a [message] at a particular [logLevel] if | 131 * Adds a log record for a [message] at a particular [logLevel] if |
| 132 * `isLoggable(logLevel)` is true. | 132 * `isLoggable(logLevel)` is true. |
| 133 * | 133 * |
| 134 * Use this method to create log entries for user-defined levels. To record a | 134 * Use this method to create log entries for user-defined levels. To record a |
| 135 * message at a predefined level (e.g. [Level.INFO], [Level.WARNING], etc) you | 135 * message at a predefined level (e.g. [Level.INFO], [Level.WARNING], etc) you |
| 136 * can use their specialized methods instead (e.g. [info], [warning], etc). | 136 * can use their specialized methods instead (e.g. [info], [warning], etc). |
| 137 * | 137 * |
| 138 * If [message] is a [Function], it will be lazy evaluated. Additionally, if | 138 * If [message] is a [Function], it will be lazy evaluated. Additionally, if |
| 139 * [message] or its evaluated value is not a [String], then 'toString()' will | 139 * [message] or its evaluated value is not a [String], then 'toString()' will |
| 140 * be called on it and the result will be logged. | 140 * be called on it and the result will be logged. |
|
Søren Gjesse
2014/12/09 07:48:35
Please update the comment with the information tha
kustermann
2015/01/07 12:38:44
Done.
| |
| 141 */ | 141 */ |
| 142 void log(Level logLevel, message, [Object error, StackTrace stackTrace]) { | 142 void log(Level logLevel, message, [Object error, StackTrace stackTrace]) { |
|
Søren Gjesse
2014/12/09 07:48:35
Would it make sense to make it possible to overrid
kustermann
2015/01/07 12:38:44
Done.
| |
| 143 if (isLoggable(logLevel)) { | 143 if (isLoggable(logLevel)) { |
| 144 // If message is a Function, evaluate it. | 144 // If message is a Function, evaluate it. |
| 145 if (message is Function) message = message(); | 145 if (message is Function) message = message(); |
| 146 // If message is still not a String, call toString(). | 146 // If message is still not a String, call toString(). |
| 147 if (message is! String) message = message.toString(); | 147 if (message is! String) message = message.toString(); |
| 148 | 148 |
| 149 var record = new LogRecord(logLevel, message, fullName, error, | 149 var record = new LogRecord(logLevel, message, fullName, error, |
| 150 stackTrace); | 150 stackTrace, Zone.current); |
| 151 | 151 |
| 152 if (hierarchicalLoggingEnabled) { | 152 if (hierarchicalLoggingEnabled) { |
| 153 var target = this; | 153 var target = this; |
| 154 while (target != null) { | 154 while (target != null) { |
| 155 target._publish(record); | 155 target._publish(record); |
| 156 target = target.parent; | 156 target = target.parent; |
| 157 } | 157 } |
| 158 } else { | 158 } else { |
| 159 root._publish(record); | 159 root._publish(record); |
| 160 } | 160 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 final int sequenceNumber; | 307 final int sequenceNumber; |
| 308 | 308 |
| 309 static int _nextNumber = 0; | 309 static int _nextNumber = 0; |
| 310 | 310 |
| 311 /** Associated error (if any) when recording errors messages. */ | 311 /** Associated error (if any) when recording errors messages. */ |
| 312 final Object error; | 312 final Object error; |
| 313 | 313 |
| 314 /** Associated stackTrace (if any) when recording errors messages. */ | 314 /** Associated stackTrace (if any) when recording errors messages. */ |
| 315 final StackTrace stackTrace; | 315 final StackTrace stackTrace; |
| 316 | 316 |
| 317 /** Zone of the calling code which resulted in this LogRecord. */ | |
| 318 final Zone zone; | |
| 319 | |
| 317 LogRecord(this.level, this.message, this.loggerName, [this.error, | 320 LogRecord(this.level, this.message, this.loggerName, [this.error, |
|
Søren Gjesse
2014/12/09 07:48:35
I know that this is not related to you change, but
kustermann
2015/01/07 12:38:44
That would be a breaking change and I don't intent
| |
| 318 this.stackTrace]) | 321 this.stackTrace, |
| 322 this.zone]) | |
| 319 : time = new DateTime.now(), | 323 : time = new DateTime.now(), |
| 320 sequenceNumber = LogRecord._nextNumber++; | 324 sequenceNumber = LogRecord._nextNumber++; |
| 321 | 325 |
| 322 String toString() => '[${level.name}] $loggerName: $message'; | 326 String toString() => '[${level.name}] $loggerName: $message'; |
| 323 } | 327 } |
| OLD | NEW |