| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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. |
| 141 * |
| 142 * The log record will contain a field for the zone in which this call was |
| 143 * made. |
| 144 * This can be advantagous if a log listener wants to handle records of |
| 145 * different zones differently (e.g. group log records by http-request if each |
| 146 * http-request handler runs in it's own zone). |
| 141 */ | 147 */ |
| 142 void log(Level logLevel, message, [Object error, StackTrace stackTrace]) { | 148 void log(Level logLevel, |
| 149 message, |
| 150 [Object error, StackTrace stackTrace, Zone zone]) { |
| 143 if (isLoggable(logLevel)) { | 151 if (isLoggable(logLevel)) { |
| 144 // If message is a Function, evaluate it. | 152 // If message is a Function, evaluate it. |
| 145 if (message is Function) message = message(); | 153 if (message is Function) message = message(); |
| 146 // If message is still not a String, call toString(). | 154 // If message is still not a String, call toString(). |
| 147 if (message is! String) message = message.toString(); | 155 if (message is! String) message = message.toString(); |
| 156 // Only record the current zone if it was not given. |
| 157 if (zone == null) zone = Zone.current; |
| 148 | 158 |
| 149 var record = new LogRecord(logLevel, message, fullName, error, | 159 var record = new LogRecord(logLevel, message, fullName, error, |
| 150 stackTrace); | 160 stackTrace, zone); |
| 151 | 161 |
| 152 if (hierarchicalLoggingEnabled) { | 162 if (hierarchicalLoggingEnabled) { |
| 153 var target = this; | 163 var target = this; |
| 154 while (target != null) { | 164 while (target != null) { |
| 155 target._publish(record); | 165 target._publish(record); |
| 156 target = target.parent; | 166 target = target.parent; |
| 157 } | 167 } |
| 158 } else { | 168 } else { |
| 159 root._publish(record); | 169 root._publish(record); |
| 160 } | 170 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 final int sequenceNumber; | 317 final int sequenceNumber; |
| 308 | 318 |
| 309 static int _nextNumber = 0; | 319 static int _nextNumber = 0; |
| 310 | 320 |
| 311 /** Associated error (if any) when recording errors messages. */ | 321 /** Associated error (if any) when recording errors messages. */ |
| 312 final Object error; | 322 final Object error; |
| 313 | 323 |
| 314 /** Associated stackTrace (if any) when recording errors messages. */ | 324 /** Associated stackTrace (if any) when recording errors messages. */ |
| 315 final StackTrace stackTrace; | 325 final StackTrace stackTrace; |
| 316 | 326 |
| 327 /** Zone of the calling code which resulted in this LogRecord. */ |
| 328 final Zone zone; |
| 329 |
| 317 LogRecord(this.level, this.message, this.loggerName, [this.error, | 330 LogRecord(this.level, this.message, this.loggerName, [this.error, |
| 318 this.stackTrace]) | 331 this.stackTrace, |
| 332 this.zone]) |
| 319 : time = new DateTime.now(), | 333 : time = new DateTime.now(), |
| 320 sequenceNumber = LogRecord._nextNumber++; | 334 sequenceNumber = LogRecord._nextNumber++; |
| 321 | 335 |
| 322 String toString() => '[${level.name}] $loggerName: $message'; | 336 String toString() => '[${level.name}] $loggerName: $message'; |
| 323 } | 337 } |
| OLD | NEW |