Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Friends | List of all members
dart::Log Class Reference

#include <log.h>

Public Member Functions

 Log (LogPrinter printer=nullptr)
 
 ~Log ()
 
void Print (const char *format,...) PRINTF_ATTRIBUTE(2
 
void void VPrint (const char *format, va_list args)
 
void Flush (const intptr_t cursor=0)
 
void Clear ()
 
intptr_t cursor () const
 

Static Public Member Functions

static LogCurrent ()
 
static LogNoOpLog ()
 

Friends

class LogBlock
 
class LogTestHelper
 

Detailed Description

Definition at line 27 of file log.h.

Constructor & Destructor Documentation

◆ Log()

dart::Log::Log ( LogPrinter  printer = nullptr)
explicit

Definition at line 60 of file log.cc.

60 : printer_(printer), manual_flush_(0), buffer_(0) {
61 if (printer_ == nullptr) {
62 if (FLAG_redirect_isolate_log_to == nullptr) {
63 printer_ = [](const char* data) { OS::PrintErr("%s", data); };
64 } else {
65 printer_ = &LogFile::Print;
66 }
67 }
68}
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static int8_t data[kExtLength]

◆ ~Log()

dart::Log::~Log ( )

Definition at line 70 of file log.cc.

70 {
71 // Did someone enable manual flushing and then forgot to Flush?
72 ASSERT(cursor() == 0);
73}
intptr_t cursor() const
Definition: log.cc:158
#define ASSERT(E)

Member Function Documentation

◆ Clear()

void dart::Log::Clear ( )

Definition at line 151 of file log.cc.

151 {
152 if (this == NoOpLog()) {
153 return;
154 }
155 buffer_.TruncateTo(0);
156}
void TruncateTo(intptr_t length)
static Log * NoOpLog()
Definition: log.cc:183

◆ Current()

Log * dart::Log::Current ( )
static

Definition at line 75 of file log.cc.

75 {
76 Thread* thread = Thread::Current();
77 if (thread == nullptr) {
78 OSThread* os_thread = OSThread::Current();
79 ASSERT(os_thread != nullptr);
80 return os_thread->log();
81 }
82 IsolateGroup* isolate_group = thread->isolate_group();
83 if ((isolate_group != nullptr) &&
84 Log::ShouldLogForIsolateGroup(isolate_group)) {
85 OSThread* os_thread = thread->os_thread();
86 ASSERT(os_thread != nullptr);
87 return os_thread->log();
88 } else {
89 return Log::NoOpLog();
90 }
91}
static OSThread * Current()
Definition: os_thread.h:179
static Thread * Current()
Definition: thread.h:362

◆ cursor()

intptr_t dart::Log::cursor ( ) const

Definition at line 158 of file log.cc.

158 {
159 return buffer_.length();
160}
intptr_t length() const

◆ Flush()

void dart::Log::Flush ( const intptr_t  cursor = 0)

Definition at line 134 of file log.cc.

134 {
135 if (this == NoOpLog()) {
136 return;
137 }
138 if (buffer_.is_empty()) {
139 return;
140 }
141 if (buffer_.length() <= cursor) {
142 return;
143 }
144 TerminateString();
145 const char* str = &buffer_[cursor];
146 ASSERT(str != nullptr);
147 printer_(str);
148 buffer_.TruncateTo(cursor);
149}

◆ NoOpLog()

Log * dart::Log::NoOpLog ( )
static

Definition at line 183 of file log.cc.

183 {
184 return &noop_log_;
185}

◆ Print()

void dart::Log::Print ( const char *  format,
  ... 
)

Definition at line 93 of file log.cc.

93 {
94 if (this == NoOpLog()) {
95 return;
96 }
97
98 va_list args;
101 va_end(args);
102}
void void VPrint(const char *format, va_list args)
Definition: log.cc:104
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
uint32_t uint32_t * format
va_start(args, format)
va_end(args)

◆ VPrint()

void dart::Log::VPrint ( const char *  format,
va_list  args 
)

Definition at line 104 of file log.cc.

104 {
105 if (this == NoOpLog()) {
106 return;
107 }
108
109 // Measure.
110 va_list measure_args;
111 va_copy(measure_args, args);
112 intptr_t len = Utils::VSNPrint(nullptr, 0, format, measure_args);
113 va_end(measure_args);
114
115 // Print.
116 char* buffer = reinterpret_cast<char*>(malloc(len + 1));
117 va_list print_args;
118 va_copy(print_args, args);
119 Utils::VSNPrint(buffer, (len + 1), format, print_args);
120 va_end(print_args);
121
122 // Append.
123 // NOTE: does not append the '\0' character.
124 for (intptr_t i = 0; i < len; i++) {
125 buffer_.Add(buffer[i]);
126 }
127 free(buffer);
128
129 if (ShouldFlush()) {
130 Flush();
131 }
132}
void Add(const T &value)
void Flush(const intptr_t cursor=0)
Definition: log.cc:134
static int static int VSNPrint(char *str, size_t size, const char *format, va_list args)
void * malloc(size_t size)
Definition: allocation.cc:19
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

Friends And Related Function Documentation

◆ LogBlock

friend class LogBlock
friend

Definition at line 68 of file log.h.

◆ LogTestHelper

friend class LogTestHelper
friend

Definition at line 69 of file log.h.


The documentation for this class was generated from the following files: