| Index: packages/logging/lib/logging.dart
|
| diff --git a/packages/logging/lib/logging.dart b/packages/logging/lib/logging.dart
|
| index 493d8599584b1ffeba5f872e8691644fa840df1a..9a7e5317ca01c63482565dd0827473262d174e1d 100644
|
| --- a/packages/logging/lib/logging.dart
|
| +++ b/packages/logging/lib/logging.dart
|
| @@ -9,27 +9,27 @@ library logging;
|
| import 'dart:async';
|
| import 'dart:collection';
|
|
|
| -/**
|
| - * Whether to allow fine-grain logging and configuration of loggers in a
|
| - * hierarchy. When false, all logging is merged in the root logger.
|
| - */
|
| +/// Whether to allow fine-grain logging and configuration of loggers in a
|
| +/// hierarchy.
|
| +///
|
| +/// When false, all logging is merged in the root logger.
|
| bool hierarchicalLoggingEnabled = false;
|
|
|
| -/**
|
| - * Automatically record stack traces for any message of this level or above.
|
| - * Because this is expensive, this is off by default.
|
| - */
|
| +/// Automatically record stack traces for any message of this level or above.
|
| +///
|
| +/// Because this is expensive, this is off by default.
|
| Level recordStackTraceAtLevel = Level.OFF;
|
|
|
| -/**
|
| - * Level for the root-logger. This will be the level of all loggers if
|
| - * [hierarchicalLoggingEnabled] is false.
|
| - */
|
| +/// Level for the root-logger.
|
| +///
|
| +/// This will be the level of all loggers if [hierarchicalLoggingEnabled] is
|
| +/// false.
|
| Level _rootLevel = Level.INFO;
|
|
|
| /**
|
| - * Use a [Logger] to log debug messages. [Logger]s are named using a
|
| - * hierarchical dot-separated name convention.
|
| + * Use a [Logger] to log debug messages.
|
| + *
|
| + * [Logger]s are named using a hierarchical dot-separated name convention.
|
| */
|
| class Logger {
|
| /** Simple name of this logger. */
|
| @@ -65,7 +65,7 @@ class Logger {
|
| ///
|
| /// Returns a new [Logger] instance (unlike `new Logger`, which returns a
|
| /// [Logger] singleton), which doesn't have any parent or children,
|
| - /// and it's not a part of the global hierarchial loggers structure.
|
| + /// and is not a part of the global hierarchical loggers structure.
|
| ///
|
| /// It can be useful when you just need a local short-living logger,
|
| /// which you'd like to be garbage-collected later.
|
| @@ -123,11 +123,13 @@ class Logger {
|
| }
|
| }
|
|
|
| - /**
|
| - * Returns an stream of messages added to this [Logger]. You can listen for
|
| - * messages using the standard stream APIs, for instance:
|
| - * logger.onRecord.listen((record) { ... });
|
| - */
|
| + /// Returns a stream of messages added to this [Logger].
|
| + ///
|
| + /// You can listen for messages using the standard stream APIs, for instance:
|
| + ///
|
| + /// ```dart
|
| + /// logger.onRecord.listen((record) { ... });
|
| + /// ```
|
| Stream<LogRecord> get onRecord => _getStream();
|
|
|
| void clearListeners() {
|
| @@ -144,29 +146,32 @@ class Logger {
|
| /** Whether a message for [value]'s level is loggable in this logger. */
|
| bool isLoggable(Level value) => (value >= level);
|
|
|
| - /**
|
| - * Adds a log record for a [message] at a particular [logLevel] if
|
| - * `isLoggable(logLevel)` is true.
|
| - *
|
| - * Use this method to create log entries for user-defined levels. To record a
|
| - * message at a predefined level (e.g. [Level.INFO], [Level.WARNING], etc) you
|
| - * can use their specialized methods instead (e.g. [info], [warning], etc).
|
| - *
|
| - * If [message] is a [Function], it will be lazy evaluated. Additionally, if
|
| - * [message] or its evaluated value is not a [String], then 'toString()' will
|
| - * be called on it and the result will be logged.
|
| - *
|
| - * The log record will contain a field for the zone in which this call was
|
| - * made.
|
| - * This can be advantagous if a log listener wants to handle records of
|
| - * different zones differently (e.g. group log records by http-request if each
|
| - * http-request handler runs in it's own zone).
|
| - */
|
| + /// Adds a log record for a [message] at a particular [logLevel] if
|
| + /// `isLoggable(logLevel)` is true.
|
| + ///
|
| + /// Use this method to create log entries for user-defined levels. To record a
|
| + /// message at a predefined level (e.g. [Level.INFO], [Level.WARNING], etc)
|
| + /// you can use their specialized methods instead (e.g. [info], [warning],
|
| + /// etc).
|
| + ///
|
| + /// If [message] is a [Function], it will be lazy evaluated. Additionally, if
|
| + /// [message] or its evaluated value is not a [String], then 'toString()' will
|
| + /// be called on the object and the result will be logged. The log record will
|
| + /// contain a field holding the original object.
|
| + ///
|
| + /// The log record will also contain a field for the zone in which this call
|
| + /// was made. This can be advantageous if a log listener wants to handler
|
| + /// records of different zones differently (e.g. group log records by HTTP
|
| + /// request if each HTTP request handler runs in it's own zone).
|
| void log(Level logLevel, message,
|
| [Object error, StackTrace stackTrace, Zone zone]) {
|
| + Object object;
|
| if (isLoggable(logLevel)) {
|
| if (message is Function) message = message();
|
| - if (message is! String) message = message.toString();
|
| + if (message is! String) {
|
| + object = message;
|
| + message = message.toString();
|
| + }
|
| if (stackTrace == null && logLevel >= recordStackTraceAtLevel) {
|
| try {
|
| throw "autogenerated stack trace for $logLevel $message";
|
| @@ -177,8 +182,8 @@ class Logger {
|
| }
|
| if (zone == null) zone = Zone.current;
|
|
|
| - var record =
|
| - new LogRecord(logLevel, message, fullName, error, stackTrace, zone);
|
| + var record = new LogRecord(
|
| + logLevel, message, fullName, error, stackTrace, zone, object);
|
|
|
| if (hierarchicalLoggingEnabled) {
|
| var target = this;
|
| @@ -335,6 +340,9 @@ class LogRecord {
|
| final Level level;
|
| final String message;
|
|
|
| + /** Non-string message passed to Logger. */
|
| + final Object object;
|
| +
|
| /** Logger where this record is stored. */
|
| final String loggerName;
|
|
|
| @@ -356,7 +364,7 @@ class LogRecord {
|
| final Zone zone;
|
|
|
| LogRecord(this.level, this.message, this.loggerName,
|
| - [this.error, this.stackTrace, this.zone])
|
| + [this.error, this.stackTrace, this.zone, this.object])
|
| : time = new DateTime.now(),
|
| sequenceNumber = LogRecord._nextNumber++;
|
|
|
|
|