Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
fml::LogMessage Class Reference

#include <logging.h>

Public Member Functions

 LogMessage (LogSeverity severity, const char *file, int line, const char *condition)
 
 ~LogMessage ()
 
std::ostream & stream ()
 

Static Public Member Functions

static void CaptureNextLog (std::ostringstream *stream)
 

Detailed Description

Definition at line 32 of file logging.h.

Constructor & Destructor Documentation

◆ LogMessage()

fml::LogMessage::LogMessage ( LogSeverity  severity,
const char *  file,
int  line,
const char *  condition 
)

Definition at line 89 of file logging.cc.

93 : severity_(severity), file_(StripDots(file)), line_(line) {
94#if !defined(OS_FUCHSIA)
95 stream_ << "[";
96 if (severity >= kLogInfo) {
97 stream_ << GetNameForLogSeverity(severity);
98 } else {
99 stream_ << "VERBOSE" << -severity;
100 }
101 stream_ << ":" << file_ << "(" << line_ << ")] ";
102#endif
103
104 if (condition) {
105 stream_ << "Check failed: " << condition << ". ";
106 }
107}
constexpr LogSeverity kLogInfo
Definition: log_level.h:13

◆ ~LogMessage()

fml::LogMessage::~LogMessage ( )

Definition at line 133 of file logging.cc.

133 {
134#if !defined(OS_FUCHSIA)
135 stream_ << std::endl;
136#endif
137 if (capture_next_log_stream_) {
138 *capture_next_log_stream_ << stream_.str();
139 capture_next_log_stream_ = nullptr;
140 } else {
141#if defined(FML_OS_ANDROID)
142 android_LogPriority priority =
143 (severity_ < 0) ? ANDROID_LOG_VERBOSE : ANDROID_LOG_UNKNOWN;
144 switch (severity_) {
145 case kLogImportant:
146 case kLogInfo:
147 priority = ANDROID_LOG_INFO;
148 break;
149 case kLogWarning:
150 priority = ANDROID_LOG_WARN;
151 break;
152 case kLogError:
153 priority = ANDROID_LOG_ERROR;
154 break;
155 case kLogFatal:
156 priority = ANDROID_LOG_FATAL;
157 break;
158 }
159 __android_log_write(priority, "flutter", stream_.str().c_str());
160#elif defined(FML_OS_IOS)
161 syslog(LOG_ALERT, "%s", stream_.str().c_str());
162#elif defined(OS_FUCHSIA)
163 FuchsiaLogSeverity severity;
164 switch (severity_) {
165 case kLogImportant:
166 case kLogInfo:
167 severity = FUCHSIA_LOG_INFO;
168 break;
169 case kLogWarning:
170 severity = FUCHSIA_LOG_WARNING;
171 break;
172 case kLogError:
173 severity = FUCHSIA_LOG_ERROR;
174 break;
175 case kLogFatal:
176 severity = FUCHSIA_LOG_FATAL;
177 break;
178 default:
179 if (severity_ < 0) {
180 severity = FUCHSIA_LOG_DEBUG;
181 } else {
182 // Unknown severity. Use INFO.
183 severity = FUCHSIA_LOG_INFO;
184 }
185 break;
186 }
187 fuchsia_syslog::LogBuffer buffer;
188 buffer.BeginRecord(severity, std::string_view(file_), line_,
189 std::string_view(stream_.str()), socket.borrow(), 0, pid,
190 tid);
191 if (!process_name.empty()) {
192 buffer.WriteKeyValue("tag", process_name);
193 }
194 if (auto tags_ptr = LogState::Default().tags()) {
195 for (auto& tag : *tags_ptr) {
196 buffer.WriteKeyValue("tag", tag);
197 }
198 }
199 buffer.FlushRecord();
200#else
201 // Don't use std::cerr here, because it may not be initialized properly yet.
202 fprintf(stderr, "%s", stream_.str().c_str());
203 fflush(stderr);
204#endif
205 }
206
207 if (severity_ >= kLogFatal) {
208 KillProcess();
209 }
210}
static LogState & Default()
Definition: log_state.cc:61
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
void KillProcess()
Definition: logging.cc:220
constexpr LogSeverity kLogFatal
Definition: log_level.h:19
constexpr LogSeverity kLogImportant
Definition: log_level.h:18
constexpr LogSeverity kLogError
Definition: log_level.h:15
constexpr LogSeverity kLogWarning
Definition: log_level.h:14

Member Function Documentation

◆ CaptureNextLog()

void fml::LogMessage::CaptureNextLog ( std::ostringstream *  stream)
static

Definition at line 129 of file logging.cc.

129 {
130 LogMessage::capture_next_log_stream_ = stream;
131}
std::ostream & stream()
Definition: logging.h:40

◆ stream()

std::ostream & fml::LogMessage::stream ( )
inline

Definition at line 40 of file logging.h.

40{ return stream_; }

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