9#include "flutter/fml/build_config.h"
10#include "flutter/fml/log_level.h"
11#include "flutter/fml/log_settings.h"
12#include "flutter/fml/logging.h"
14#if defined(FML_OS_ANDROID)
15#include <android/log.h>
16#elif defined(FML_OS_IOS)
18#elif defined(OS_FUCHSIA)
19#include <lib/syslog/structured_backend/cpp/fuchsia_syslog.h>
20#include <lib/syslog/structured_backend/fuchsia_syslog.h>
21#include <zircon/process.h>
22#include "flutter/fml/platform/fuchsia/log_state.h"
29#if !defined(OS_FUCHSIA)
31 "INFO",
"WARNING",
"ERROR",
"IMPORTANT",
"FATAL"};
33const char* GetNameForLogSeverity(
LogSeverity severity) {
35 return kLogSeverityNames[severity];
41const char* StripDots(
const char*
path) {
42 while (strncmp(
path,
"../", 3) == 0) {
48#if defined(OS_FUCHSIA)
50zx_koid_t GetKoid(zx_handle_t handle) {
51 zx_info_handle_basic_t
info;
52 zx_status_t status = zx_object_get_info(handle, ZX_INFO_HANDLE_BASIC, &
info,
53 sizeof(
info),
nullptr,
nullptr);
54 return status == ZX_OK ?
info.koid : ZX_KOID_INVALID;
57thread_local zx_koid_t tls_thread_koid{ZX_KOID_INVALID};
59zx_koid_t GetCurrentThreadKoid() {
60 if (unlikely(tls_thread_koid == ZX_KOID_INVALID)) {
61 tls_thread_koid = GetKoid(zx_thread_self());
63 ZX_DEBUG_ASSERT(tls_thread_koid != ZX_KOID_INVALID);
64 return tls_thread_koid;
67static zx_koid_t pid = GetKoid(zx_process_self());
69static thread_local zx_koid_t tid = GetCurrentThreadKoid();
71std::string GetProcessName(zx_handle_t handle) {
72 char process_name[ZX_MAX_NAME_LEN];
73 zx_status_t status = zx_object_get_property(
74 handle, ZX_PROP_NAME, &process_name,
sizeof(process_name));
75 if (status != ZX_OK) {
76 process_name[0] =
'\0';
81static std::string process_name = GetProcessName(zx_process_self());
92 const char* condition)
93 : severity_(severity), file_(StripDots(
file)), line_(
line) {
94#if !defined(OS_FUCHSIA)
97 stream_ << GetNameForLogSeverity(severity);
99 stream_ <<
"VERBOSE" << -severity;
101 stream_ <<
":" << file_ <<
"(" << line_ <<
")] ";
105 stream_ <<
"Check failed: " << condition <<
". ";
110thread_local std::ostringstream* LogMessage::capture_next_log_stream_ =
nullptr;
123 return stream_.str();
130 LogMessage::capture_next_log_stream_ =
stream;
134#if !defined(OS_FUCHSIA)
135 stream_ << std::endl;
137 if (capture_next_log_stream_) {
138 *capture_next_log_stream_ << stream_.str();
139 capture_next_log_stream_ =
nullptr;
141#if defined(FML_OS_ANDROID)
142 android_LogPriority priority =
143 (severity_ < 0) ? ANDROID_LOG_VERBOSE : ANDROID_LOG_UNKNOWN;
147 priority = ANDROID_LOG_INFO;
150 priority = ANDROID_LOG_WARN;
153 priority = ANDROID_LOG_ERROR;
156 priority = ANDROID_LOG_FATAL;
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;
167 severity = FUCHSIA_LOG_INFO;
170 severity = FUCHSIA_LOG_WARNING;
173 severity = FUCHSIA_LOG_ERROR;
176 severity = FUCHSIA_LOG_FATAL;
180 severity = FUCHSIA_LOG_DEBUG;
183 severity = FUCHSIA_LOG_INFO;
187 fuchsia_syslog::LogBuffer
buffer;
188 buffer.BeginRecord(severity, std::string_view(file_), line_,
189 std::string_view(stream_.str()), socket.borrow(), 0, pid,
191 if (!process_name.empty()) {
192 buffer.WriteKeyValue(
"tag", process_name);
195 for (
auto& tag : *tags_ptr) {
196 buffer.WriteKeyValue(
"tag", tag);
202 fprintf(stderr,
"%s", stream_.str().c_str());
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
LogMessage(LogSeverity severity, const char *file, int line, const char *condition)
static void CaptureNextLog(std::ostringstream *stream)
static LogState & Default()
const zx::socket & socket() const
static float max(float r, float g, float b)
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
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
constexpr LogSeverity kLogFatal
constexpr LogSeverity kLogNumSeverities
constexpr LogSeverity kLogImportant
bool ShouldCreateLogMessage(LogSeverity severity)
constexpr LogSeverity kLogError
constexpr LogSeverity kLogInfo
constexpr LogSeverity kLogWarning