| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/log.h" | 5 #include "vm/log.h" |
| 6 | 6 |
| 7 #include "vm/flags.h" | 7 #include "vm/flags.h" |
| 8 #include "vm/thread.h" | 8 #include "vm/thread.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| 11 | 11 |
| 12 DEFINE_FLAG(bool, force_log_flush, false, "Always flush log messages."); | 12 DEFINE_FLAG(bool, force_log_flush, false, "Always flush log messages."); |
| 13 | 13 |
| 14 DEFINE_FLAG(charp, isolate_log_filter, NULL, |
| 15 "Log isolates whose name include the filter. " |
| 16 "Default: service isolate log messages are suppressed."); |
| 17 |
| 14 Log::Log(LogPrinter printer) | 18 Log::Log(LogPrinter printer) |
| 15 : printer_(printer), | 19 : printer_(printer), |
| 16 manual_flush_(0), | 20 manual_flush_(0), |
| 17 buffer_(0) { | 21 buffer_(0) { |
| 18 } | 22 } |
| 19 | 23 |
| 20 | 24 |
| 25 Log::~Log() { |
| 26 // Did someone enable manual flushing and then forgot to Flush? |
| 27 ASSERT(cursor() == 0); |
| 28 } |
| 29 |
| 30 |
| 21 void Log::Print(const char* format, ...) { | 31 void Log::Print(const char* format, ...) { |
| 22 if (this == NoOpLog()) { | 32 if (this == NoOpLog()) { |
| 23 return; | 33 return; |
| 24 } | 34 } |
| 25 | 35 |
| 26 va_list args; | 36 va_list args; |
| 27 va_start(args, format); | 37 va_start(args, format); |
| 28 VPrint(format, args); | 38 VPrint(format, args); |
| 29 va_end(args); | 39 va_end(args); |
| 30 } | 40 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 95 } |
| 86 buffer_.TruncateTo(0); | 96 buffer_.TruncateTo(0); |
| 87 } | 97 } |
| 88 | 98 |
| 89 | 99 |
| 90 intptr_t Log::cursor() const { | 100 intptr_t Log::cursor() const { |
| 91 return buffer_.length(); | 101 return buffer_.length(); |
| 92 } | 102 } |
| 93 | 103 |
| 94 | 104 |
| 105 bool Log::ShouldLogForIsolate(const Isolate* isolate) { |
| 106 if (FLAG_isolate_log_filter == NULL) { |
| 107 if (isolate->is_service_isolate()) { |
| 108 // By default, do not log for the service isolate. |
| 109 return false; |
| 110 } |
| 111 return true; |
| 112 } |
| 113 const char* name = isolate->name(); |
| 114 ASSERT(name != NULL); |
| 115 if (strstr(name, FLAG_isolate_log_filter) == NULL) { |
| 116 // Filter does not match, do not log for this isolate. |
| 117 return false; |
| 118 } |
| 119 return true; |
| 120 } |
| 121 |
| 122 |
| 95 Log Log::noop_log_; | 123 Log Log::noop_log_; |
| 96 Log* Log::NoOpLog() { | 124 Log* Log::NoOpLog() { |
| 97 return &noop_log_; | 125 return &noop_log_; |
| 98 } | 126 } |
| 99 | 127 |
| 100 | 128 |
| 101 void Log::TerminateString() { | 129 void Log::TerminateString() { |
| 102 buffer_.Add('\0'); | 130 buffer_.Add('\0'); |
| 103 } | 131 } |
| 104 | 132 |
| 105 | 133 |
| 106 void Log::EnableManualFlush() { | 134 void Log::EnableManualFlush() { |
| 107 manual_flush_++; | 135 manual_flush_++; |
| 108 } | 136 } |
| 109 | 137 |
| 110 | 138 |
| 111 void Log::DisableManualFlush() { | 139 void Log::DisableManualFlush() { |
| 112 manual_flush_--; | 140 manual_flush_--; |
| 113 ASSERT(manual_flush_ >= 0); | 141 ASSERT(manual_flush_ >= 0); |
| 114 if (manual_flush_ == 0) { | 142 if (manual_flush_ == 0) { |
| 115 Flush(); | 143 Flush(); |
| 116 } | 144 } |
| 117 } | 145 } |
| 118 | 146 |
| 119 | 147 |
| 120 LogBlock::LogBlock(Thread* thread, Log* log) | 148 void LogBlock::Initialize(class Log* log) { |
| 121 : StackResource(thread), | 149 log_ = log; |
| 122 log_(log), cursor_(log->cursor()) { | 150 cursor_ = log->cursor(); |
| 123 CommonConstructor(); | 151 log_->EnableManualFlush(); |
| 124 } | 152 } |
| 125 | 153 |
| 126 | 154 |
| 127 LogBlock::LogBlock(Isolate* isolate) | 155 LogBlock::~LogBlock() { |
| 128 : StackResource(isolate), | 156 log_->Flush(cursor_); |
| 129 log_(isolate->Log()), cursor_(isolate->Log()->cursor()) { | 157 log_->DisableManualFlush(); |
| 130 CommonConstructor(); | |
| 131 } | |
| 132 | |
| 133 | |
| 134 LogBlock::LogBlock(Thread* thread) | |
| 135 : StackResource(thread), | |
| 136 log_(thread->isolate()->Log()), | |
| 137 cursor_(thread->isolate()->Log()->cursor()) { | |
| 138 CommonConstructor(); | |
| 139 } | 158 } |
| 140 | 159 |
| 141 } // namespace dart | 160 } // namespace dart |
| OLD | NEW |