Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 #ifndef VM_LOG_H_ | |
| 6 #define VM_LOG_H_ | |
| 7 | |
| 8 #include "vm/allocation.h" | |
| 9 #include "vm/growable_array.h" | |
| 10 #include "vm/os.h" | |
| 11 | |
| 12 namespace dart { | |
| 13 | |
| 14 class Isolate; | |
| 15 class LogBlock; | |
| 16 | |
| 17 #define ISO_Print(format, ...) \ | |
| 18 Isolate::Current()->Log()->Print(format, ##__VA_ARGS__) | |
| 19 | |
| 20 typedef void (*LogPrinter)(const char* str, ...); | |
| 21 | |
| 22 class Log { | |
| 23 public: | |
| 24 explicit Log(LogPrinter printer = OS::Print); | |
| 25 ~Log(); | |
|
srdjan
2015/02/09 18:01:02
virtual ~Log();
Cutch
2015/02/09 18:19:39
Why? There are no virtual methods.
| |
| 26 | |
| 27 // Append a formatted string to the log. | |
| 28 void Print(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); | |
| 29 | |
| 30 // Append to the log. | |
| 31 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.
| |
| 32 | |
| 33 // Flush and truncate the log. The log is flushed starting at cursor | |
| 34 // and truncated to cursor afterwards. | |
| 35 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.
| |
| 36 | |
| 37 // Clears the log. | |
| 38 void Clear(); | |
| 39 | |
| 40 // Current cursor. | |
| 41 intptr_t cursor() const; | |
| 42 | |
| 43 // A logger that does nothing. | |
| 44 static Log* NoOpLog(); | |
| 45 | |
| 46 private: | |
| 47 void TerminateString(); | |
| 48 void EnableManualFlush(); | |
| 49 void DisableManualFlush(); | |
| 50 | |
| 51 static Log noop_log_; | |
| 52 LogPrinter printer_; | |
| 53 intptr_t manual_flush_; | |
| 54 MallocGrowableArray<char> buffer_; | |
| 55 | |
| 56 friend class LogBlock; | |
| 57 friend class LogTestHelper; | |
| 58 DISALLOW_COPY_AND_ASSIGN(Log); | |
| 59 }; | |
| 60 | |
| 61 | |
| 62 class LogBlock : public StackResource { | |
| 63 public: | |
| 64 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.
| |
| 65 : StackResource(isolate), | |
| 66 log_(log), cursor_(log->cursor()) { | |
| 67 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
| |
| 68 } | |
| 69 | |
| 70 ~LogBlock() { | |
| 71 log_->Flush(cursor_); | |
| 72 log_->DisableManualFlush(); | |
| 73 } | |
| 74 | |
| 75 private: | |
| 76 Log* log_; | |
| 77 intptr_t cursor_; | |
| 78 }; | |
| 79 | |
| 80 } // namespace dart | |
| 81 | |
| 82 #endif // VM_LOG_H_ | |
| OLD | NEW |