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

Unified Diff: pkg/analyzer/lib/src/generated/incremental_logger.dart

Issue 780643002: More work on logging - new classes and timers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/generated/incremental_logger.dart
diff --git a/pkg/analyzer/lib/src/generated/incremental_logger.dart b/pkg/analyzer/lib/src/generated/incremental_logger.dart
index 695fbc055c388c9f30b7b673c94c0dddfaac9f4e..8ab76cbd37b63f6367e0d5cf229c2d6424f7b79d 100644
--- a/pkg/analyzer/lib/src/generated/incremental_logger.dart
+++ b/pkg/analyzer/lib/src/generated/incremental_logger.dart
@@ -9,7 +9,17 @@ library engine.incremental_logger;
* The shared instance of [Logger] used by several incremental resolution
* classes. It is initialized externally by the Analysis Engine client.
*/
-Logger logger = new NullLogger();
+Logger logger = NULL_LOGGER;
+
+/**
+ * An instance of [Logger] that does not print anything.
+ */
+final Logger NULL_LOGGER = new _NullLogger();
+
+/**
+ * An instance of [Logger] that uses `print` for output.
+ */
+final Logger PRINT_LOGGER = new StringSinkLogger(new _PrintStringSink());
/**
@@ -30,23 +40,31 @@ abstract class Logger {
* Logs the given [obj].
*/
void log(Object obj);
+
+ /**
+ * Starts a new timer.
+ */
+ LoggerTimer startTimer();
}
/**
- * A [Logger] that does nothing.
+ * The handle of a timer.
*/
-class NullLogger implements Logger {
- @override
- void enter(String name) {
- }
+class LoggerTimer {
Brian Wilkerson 2014/12/03 19:31:12 nit: Perhaps "LoggingTimer"?
scheglov 2014/12/03 19:46:35 Done.
+ final Logger _logger;
+ final Stopwatch _stopwatch = new Stopwatch();
- @override
- void exit() {
+ LoggerTimer(this._logger) {
+ _stopwatch.start();
}
- @override
- void log(Object obj) {
+ /**
+ * This methods stop the timer and logs the elapsed time.
+ */
+ void stop(String message) {
+ _stopwatch.stop();
+ _logger.log('$message in ${_stopwatch.elapsedMilliseconds} ms');
}
}
@@ -87,10 +105,18 @@ class StringSinkLogger implements Logger {
_sink.writeln(line);
}
+ @override
+ LoggerTimer startTimer() {
+ return new LoggerTimer(this);
+ }
+
String _getObjectString(Object obj) {
if (obj == null) {
return 'null';
}
+ if (obj is Function) {
+ obj = obj();
+ }
String str = obj.toString();
if (str.length < _MAX_LINE_LENGTH) {
return str;
@@ -111,3 +137,60 @@ class _LoggerSection {
final String name;
_LoggerSection(this.indent, this.name);
}
+
+
+/**
+ * A [Logger] that does nothing.
+ */
+class _NullLogger implements Logger {
+ @override
+ void enter(String name) {
+ }
+
+ @override
+ void exit() {
+ }
+
+ @override
+ void log(Object obj) {
+ }
+
+ @override
+ LoggerTimer startTimer() {
+ return new LoggerTimer(this);
+ }
+}
+
+
+/**
+ * A [StringSink] implementation that uses `print`.
+ */
+class _PrintStringSink implements StringSink {
+ String _line = '';
+
+ @override
+ void write(Object obj) {
+ if (obj == null) {
+ _line += 'null';
+ } else {
+ _line += obj.toString();
+ }
+ }
+
+ @override
+ void writeAll(Iterable objects, [String separator = '']) {
+ _line += objects.join(separator);
+ }
+
+ @override
+ void writeCharCode(int charCode) {
+ _line += new String.fromCharCode(charCode);
+ }
+
+ @override
+ void writeln([Object obj = '']) {
+ _line += obj;
+ print(_line);
+ _line = '';
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698