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 class Thread; | |
| 17 | |
| 18 #define ISO_Print(format, ...) \ | |
| 19 Isolate::Current()->Log()->Print(format, ##__VA_ARGS__) | |
|
srdjan
2015/02/09 18:34:17
When reading ISO_Print, I think of a standardized
Cutch
2015/02/09 18:51:20
Done.
| |
| 20 | |
| 21 typedef void (*LogPrinter)(const char* str, ...); | |
| 22 | |
| 23 class Log { | |
| 24 public: | |
| 25 explicit Log(LogPrinter printer = OS::Print); | |
| 26 | |
| 27 // Append a formatted string to the log. | |
| 28 void Print(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); | |
| 29 | |
| 30 // Flush and truncate the log. The log is flushed starting at cursor | |
| 31 // and truncated to cursor afterwards. | |
| 32 void Flush(const intptr_t cursor = 0); | |
| 33 | |
| 34 // Clears the log. | |
| 35 void Clear(); | |
| 36 | |
| 37 // Current cursor. | |
| 38 intptr_t cursor() const; | |
| 39 | |
| 40 // A logger that does nothing. | |
| 41 static Log* NoOpLog(); | |
| 42 | |
| 43 private: | |
| 44 void TerminateString(); | |
| 45 void EnableManualFlush(); | |
| 46 void DisableManualFlush(); | |
| 47 | |
| 48 static Log noop_log_; | |
| 49 LogPrinter printer_; | |
| 50 intptr_t manual_flush_; | |
| 51 MallocGrowableArray<char> buffer_; | |
| 52 | |
| 53 friend class LogBlock; | |
| 54 friend class LogTestHelper; | |
| 55 DISALLOW_COPY_AND_ASSIGN(Log); | |
| 56 }; | |
| 57 | |
| 58 | |
| 59 class LogBlock : public StackResource { | |
|
srdjan
2015/02/09 18:34:17
Please add a brief comment.
Cutch
2015/02/09 18:51:20
Done.
| |
| 60 public: | |
| 61 LogBlock(Isolate* isolate, Log* log) | |
| 62 : StackResource(isolate), | |
| 63 log_(log), cursor_(log->cursor()) { | |
| 64 CommonConstructor(); | |
| 65 } | |
| 66 | |
| 67 explicit LogBlock(Isolate* isolate); | |
| 68 explicit LogBlock(Thread* thread); | |
| 69 | |
| 70 LogBlock(Thread* thread, Log* log); | |
| 71 | |
| 72 ~LogBlock() { | |
| 73 CommonDestructor(); | |
| 74 } | |
| 75 | |
| 76 private: | |
| 77 void CommonConstructor() { | |
| 78 log_->EnableManualFlush(); | |
| 79 } | |
| 80 | |
| 81 void CommonDestructor() { | |
| 82 log_->Flush(cursor_); | |
| 83 log_->DisableManualFlush(); | |
| 84 } | |
| 85 Log* log_; | |
| 86 intptr_t cursor_; | |
|
srdjan
2015/02/09 18:34:17
const ?
Cutch
2015/02/09 18:51:20
Done.
| |
| 87 }; | |
| 88 | |
| 89 } // namespace dart | |
| 90 | |
| 91 #endif // VM_LOG_H_ | |
| OLD | NEW |