Index: runtime/vm/log.h |
diff --git a/runtime/vm/log.h b/runtime/vm/log.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..436bb5f80cb10ae7dde5f3d7ca31d52a8ec74366 |
--- /dev/null |
+++ b/runtime/vm/log.h |
@@ -0,0 +1,82 @@ |
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+#ifndef VM_LOG_H_ |
+#define VM_LOG_H_ |
+ |
+#include "vm/allocation.h" |
+#include "vm/growable_array.h" |
+#include "vm/os.h" |
+ |
+namespace dart { |
+ |
+class Isolate; |
+class LogBlock; |
+ |
+#define ISO_Print(format, ...) \ |
+ Isolate::Current()->Log()->Print(format, ##__VA_ARGS__) |
+ |
+typedef void (*LogPrinter)(const char* str, ...); |
+ |
+class Log { |
+ public: |
+ explicit Log(LogPrinter printer = OS::Print); |
+ ~Log(); |
srdjan
2015/02/09 18:01:02
virtual ~Log();
Cutch
2015/02/09 18:19:39
Why? There are no virtual methods.
|
+ |
+ // Append a formatted string to the log. |
+ void Print(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); |
+ |
+ // Append to the log. |
+ void Append(const char* str); |
srdjan
2015/02/09 18:01:02
Why both Print and Append? Append => Print("%s", s
Cutch
2015/02/09 18:19:39
Removed Append.
|
+ |
+ // Flush and truncate the log. The log is flushed starting at cursor |
+ // and truncated to cursor afterwards. |
+ void Flush(const intptr_t cursor = 0); |
srdjan
2015/02/09 18:01:02
Do we currently need the cursor functionality?
Cutch
2015/02/09 18:19:39
Yes for LogBlocks.
|
+ |
+ // Clears the log. |
+ void Clear(); |
+ |
+ // Current cursor. |
+ intptr_t cursor() const; |
+ |
+ // A logger that does nothing. |
+ static Log* NoOpLog(); |
+ |
+ private: |
+ void TerminateString(); |
+ void EnableManualFlush(); |
+ void DisableManualFlush(); |
+ |
+ static Log noop_log_; |
+ LogPrinter printer_; |
+ intptr_t manual_flush_; |
+ MallocGrowableArray<char> buffer_; |
+ |
+ friend class LogBlock; |
+ friend class LogTestHelper; |
+ DISALLOW_COPY_AND_ASSIGN(Log); |
+}; |
+ |
+ |
+class LogBlock : public StackResource { |
+ public: |
+ LogBlock(Isolate* isolate, Log* log) |
koda
2015/02/09 17:57:29
Please add a LogBlock(Thread*) constructor (you mi
Cutch
2015/02/09 18:19:39
Done.
|
+ : StackResource(isolate), |
+ log_(log), cursor_(log->cursor()) { |
+ log_->EnableManualFlush(); |
koda
2015/02/09 17:57:29
Shouldn't 'log' usually be the same as isolate->Lo
Cutch
2015/02/09 18:19:39
Yes, but, for unit testing it's awkward to need to
|
+ } |
+ |
+ ~LogBlock() { |
+ log_->Flush(cursor_); |
+ log_->DisableManualFlush(); |
+ } |
+ |
+ private: |
+ Log* log_; |
+ intptr_t cursor_; |
+}; |
+ |
+} // namespace dart |
+ |
+#endif // VM_LOG_H_ |