[Windows] Migrate error logging to FML_LOG (flutter/engine#35367)

Migrates error logging from logging directly to stderr to using the
FML_LOG macro with a specified log level.

No additional tests since there is no semantic change to the logging
(FML_LOG simply writes to stderr).
This commit is contained in:
Chris Bracken
2022-08-12 22:19:39 -07:00
committed by GitHub
parent 1f72a47f40
commit 491db72a66
11 changed files with 66 additions and 64 deletions

View File

@@ -4,15 +4,16 @@
#include "flutter/shell/platform/windows/angle_surface_manager.h" #include "flutter/shell/platform/windows/angle_surface_manager.h"
#include <iostream>
#include <vector> #include <vector>
#include "flutter/fml/logging.h"
// Logs an EGL error to stderr. This automatically calls eglGetError() // Logs an EGL error to stderr. This automatically calls eglGetError()
// and logs the error code. // and logs the error code.
static void LogEglError(std::string message) { static void LogEglError(std::string message) {
EGLint error = eglGetError(); EGLint error = eglGetError();
std::cerr << "EGL: " << message << std::endl; FML_LOG(ERROR) << "EGL: " << message;
std::cerr << "EGL: eglGetError returned " << error << std::endl; FML_LOG(ERROR) << "EGL: eglGetError returned " << error;
} }
namespace flutter { namespace flutter {
@@ -245,8 +246,8 @@ void AngleSurfaceManager::ResizeSurface(WindowsRenderTarget* render_target,
ClearContext(); ClearContext();
DestroySurface(); DestroySurface();
if (!CreateSurface(render_target, width, height)) { if (!CreateSurface(render_target, width, height)) {
std::cerr << "AngleSurfaceManager::ResizeSurface failed to create surface" FML_LOG(ERROR)
<< std::endl; << "AngleSurfaceManager::ResizeSurface failed to create surface";
} }
} }
} }

View File

@@ -6,8 +6,8 @@
#include <EGL/egl.h> #include <EGL/egl.h>
#include <EGL/eglext.h> #include <EGL/eglext.h>
#include <iostream>
#include "flutter/fml/logging.h"
#include "flutter/shell/platform/embedder/embedder_struct_macros.h" #include "flutter/shell/platform/embedder/embedder_struct_macros.h"
namespace flutter { namespace flutter {
@@ -107,7 +107,7 @@ bool ExternalTextureD3d::CreateOrUpdateTexture(
if (egl_surface_ == EGL_NO_SURFACE || if (egl_surface_ == EGL_NO_SURFACE ||
eglBindTexImage(surface_manager_->egl_display(), egl_surface_, eglBindTexImage(surface_manager_->egl_display(), egl_surface_,
EGL_BACK_BUFFER) == EGL_FALSE) { EGL_BACK_BUFFER) == EGL_FALSE) {
std::cerr << "Binding D3D surface failed." << std::endl; FML_LOG(ERROR) << "Binding D3D surface failed.";
} }
last_surface_handle_ = handle; last_surface_handle_ = handle;
} }

View File

@@ -5,8 +5,8 @@
#include "flutter/shell/platform/windows/flutter_project_bundle.h" #include "flutter/shell/platform/windows/flutter_project_bundle.h"
#include <filesystem> #include <filesystem>
#include <iostream>
#include "flutter/fml/logging.h"
#include "flutter/shell/platform/common/engine_switches.h" // nogncheck #include "flutter/shell/platform/common/engine_switches.h" // nogncheck
#include "flutter/shell/platform/common/path_utils.h" #include "flutter/shell/platform/common/path_utils.h"
@@ -34,9 +34,8 @@ FlutterProjectBundle::FlutterProjectBundle(
(!aot_library_path_.empty() && aot_library_path_.is_relative())) { (!aot_library_path_.empty() && aot_library_path_.is_relative())) {
std::filesystem::path executable_location = GetExecutableDirectory(); std::filesystem::path executable_location = GetExecutableDirectory();
if (executable_location.empty()) { if (executable_location.empty()) {
std::cerr FML_LOG(ERROR)
<< "Unable to find executable location to resolve resource paths." << "Unable to find executable location to resolve resource paths.";
<< std::endl;
assets_path_ = std::filesystem::path(); assets_path_ = std::filesystem::path();
icu_path_ = std::filesystem::path(); icu_path_ = std::filesystem::path();
} else { } else {
@@ -59,14 +58,13 @@ bool FlutterProjectBundle::HasValidPaths() {
UniqueAotDataPtr FlutterProjectBundle::LoadAotData( UniqueAotDataPtr FlutterProjectBundle::LoadAotData(
const FlutterEngineProcTable& engine_procs) { const FlutterEngineProcTable& engine_procs) {
if (aot_library_path_.empty()) { if (aot_library_path_.empty()) {
std::cerr FML_LOG(ERROR)
<< "Attempted to load AOT data, but no aot_library_path was provided." << "Attempted to load AOT data, but no aot_library_path was provided.";
<< std::endl;
return UniqueAotDataPtr(nullptr, nullptr); return UniqueAotDataPtr(nullptr, nullptr);
} }
if (!std::filesystem::exists(aot_library_path_)) { if (!std::filesystem::exists(aot_library_path_)) {
std::cerr << "Can't load AOT data from " << aot_library_path_.u8string() FML_LOG(ERROR) << "Can't load AOT data from "
<< "; no such file." << std::endl; << aot_library_path_.u8string() << "; no such file.";
return UniqueAotDataPtr(nullptr, nullptr); return UniqueAotDataPtr(nullptr, nullptr);
} }
std::string path_string = aot_library_path_.u8string(); std::string path_string = aot_library_path_.u8string();
@@ -76,7 +74,7 @@ UniqueAotDataPtr FlutterProjectBundle::LoadAotData(
FlutterEngineAOTData data = nullptr; FlutterEngineAOTData data = nullptr;
auto result = engine_procs.CreateAOTData(&source, &data); auto result = engine_procs.CreateAOTData(&source, &data);
if (result != kSuccess) { if (result != kSuccess) {
std::cerr << "Failed to load AOT data from: " << path_string << std::endl; FML_LOG(ERROR) << "Failed to load AOT data from: " << path_string;
return UniqueAotDataPtr(nullptr, nullptr); return UniqueAotDataPtr(nullptr, nullptr);
} }
return UniqueAotDataPtr(data, engine_procs.CollectAOTData); return UniqueAotDataPtr(data, engine_procs.CollectAOTData);

View File

@@ -8,6 +8,8 @@
#include <chrono> #include <chrono>
#include <map> #include <map>
#include "flutter/fml/logging.h"
namespace flutter { namespace flutter {
namespace { namespace {
@@ -121,7 +123,7 @@ static uint64_t ConvertWinButtonToFlutterButton(UINT button) {
case XBUTTON2: case XBUTTON2:
return kFlutterPointerButtonMouseForward; return kFlutterPointerButtonMouseForward;
} }
std::cerr << "Mouse button not recognized: " << button << std::endl; FML_LOG(WARNING) << "Mouse button not recognized: " << button;
return 0; return 0;
} }

View File

@@ -10,6 +10,7 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include "flutter/fml/logging.h"
#include "flutter/fml/platform/win/wstring_conversion.h" #include "flutter/fml/platform/win/wstring_conversion.h"
#include "flutter/shell/platform/common/client_wrapper/binary_messenger_impl.h" #include "flutter/shell/platform/common/client_wrapper/binary_messenger_impl.h"
#include "flutter/shell/platform/common/path_utils.h" #include "flutter/shell/platform/common/path_utils.h"
@@ -156,17 +157,18 @@ FlutterWindowsEngine::FlutterWindowsEngine(const FlutterProjectBundle& project)
embedder_api_.struct_size = sizeof(FlutterEngineProcTable); embedder_api_.struct_size = sizeof(FlutterEngineProcTable);
FlutterEngineGetProcAddresses(&embedder_api_); FlutterEngineGetProcAddresses(&embedder_api_);
task_runner_ = std::make_unique<TaskRunner>( task_runner_ =
embedder_api_.GetCurrentTime, [this](const auto* task) { std::make_unique<TaskRunner>(
if (!engine_) { embedder_api_.GetCurrentTime, [this](const auto* task) {
std::cerr << "Cannot post an engine task when engine is not running." if (!engine_) {
<< std::endl; FML_LOG(ERROR)
return; << "Cannot post an engine task when engine is not running.";
} return;
if (embedder_api_.RunTask(engine_, task) != kSuccess) { }
std::cerr << "Failed to post an engine task." << std::endl; if (embedder_api_.RunTask(engine_, task) != kSuccess) {
} FML_LOG(ERROR) << "Failed to post an engine task.";
}); }
});
// Set up the legacy structs backing the API handles. // Set up the legacy structs backing the API handles.
messenger_ = std::make_unique<FlutterDesktopMessenger>(); messenger_ = std::make_unique<FlutterDesktopMessenger>();
@@ -206,7 +208,7 @@ bool FlutterWindowsEngine::Run() {
bool FlutterWindowsEngine::Run(std::string_view entrypoint) { bool FlutterWindowsEngine::Run(std::string_view entrypoint) {
if (!project_->HasValidPaths()) { if (!project_->HasValidPaths()) {
std::cerr << "Missing or unresolvable paths to assets." << std::endl; FML_LOG(ERROR) << "Missing or unresolvable paths to assets.";
return false; return false;
} }
std::string assets_path_string = project_->assets_path().u8string(); std::string assets_path_string = project_->assets_path().u8string();
@@ -214,7 +216,7 @@ bool FlutterWindowsEngine::Run(std::string_view entrypoint) {
if (embedder_api_.RunsAOTCompiledDartCode()) { if (embedder_api_.RunsAOTCompiledDartCode()) {
aot_data_ = project_->LoadAotData(embedder_api_); aot_data_ = project_->LoadAotData(embedder_api_);
if (!aot_data_) { if (!aot_data_) {
std::cerr << "Unable to start engine without AOT data." << std::endl; FML_LOG(ERROR) << "Unable to start engine without AOT data.";
return false; return false;
} }
} }
@@ -272,10 +274,9 @@ bool FlutterWindowsEngine::Run(std::string_view entrypoint) {
// method and only the entrypoint specified in project_ should be used. // method and only the entrypoint specified in project_ should be used.
if (!project_->dart_entrypoint().empty() && !entrypoint.empty() && if (!project_->dart_entrypoint().empty() && !entrypoint.empty() &&
project_->dart_entrypoint() != entrypoint) { project_->dart_entrypoint() != entrypoint) {
std::cerr << "Conflicting entrypoints were specified in " FML_LOG(ERROR) << "Conflicting entrypoints were specified in "
"FlutterDesktopEngineProperties.dart_entrypoint and " "FlutterDesktopEngineProperties.dart_entrypoint and "
"FlutterDesktopEngineRun(engine, entry_point). " "FlutterDesktopEngineRun(engine, entry_point). ";
<< std::endl;
return false; return false;
} }
if (!entrypoint.empty()) { if (!entrypoint.empty()) {
@@ -339,8 +340,7 @@ bool FlutterWindowsEngine::Run(std::string_view entrypoint) {
auto result = embedder_api_.Run(FLUTTER_ENGINE_VERSION, &renderer_config, auto result = embedder_api_.Run(FLUTTER_ENGINE_VERSION, &renderer_config,
&args, this, &engine_); &args, this, &engine_);
if (result != kSuccess || engine_ == nullptr) { if (result != kSuccess || engine_ == nullptr) {
std::cerr << "Failed to start Flutter engine: error " << result FML_LOG(ERROR) << "Failed to start Flutter engine: error " << result;
<< std::endl;
return false; return false;
} }
@@ -454,7 +454,7 @@ bool FlutterWindowsEngine::SendPlatformMessage(
embedder_api_.PlatformMessageCreateResponseHandle( embedder_api_.PlatformMessageCreateResponseHandle(
engine_, reply, user_data, &response_handle); engine_, reply, user_data, &response_handle);
if (result != kSuccess) { if (result != kSuccess) {
std::cout << "Failed to create response handle\n"; FML_LOG(ERROR) << "Failed to create response handle";
return false; return false;
} }
} }
@@ -486,9 +486,9 @@ void FlutterWindowsEngine::SendPlatformMessageResponse(
void FlutterWindowsEngine::HandlePlatformMessage( void FlutterWindowsEngine::HandlePlatformMessage(
const FlutterPlatformMessage* engine_message) { const FlutterPlatformMessage* engine_message) {
if (engine_message->struct_size != sizeof(FlutterPlatformMessage)) { if (engine_message->struct_size != sizeof(FlutterPlatformMessage)) {
std::cerr << "Invalid message size received. Expected: " FML_LOG(ERROR) << "Invalid message size received. Expected: "
<< sizeof(FlutterPlatformMessage) << " but received " << sizeof(FlutterPlatformMessage) << " but received "
<< engine_message->struct_size << std::endl; << engine_message->struct_size;
return; return;
} }

View File

@@ -4,9 +4,9 @@
#include "flutter/shell/platform/windows/flutter_windows_texture_registrar.h" #include "flutter/shell/platform/windows/flutter_windows_texture_registrar.h"
#include <iostream>
#include <mutex> #include <mutex>
#include "flutter/fml/logging.h"
#include "flutter/shell/platform/embedder/embedder_struct_macros.h" #include "flutter/shell/platform/embedder/embedder_struct_macros.h"
#include "flutter/shell/platform/windows/external_texture_d3d.h" #include "flutter/shell/platform/windows/external_texture_d3d.h"
#include "flutter/shell/platform/windows/external_texture_pixelbuffer.h" #include "flutter/shell/platform/windows/external_texture_pixelbuffer.h"
@@ -31,7 +31,7 @@ int64_t FlutterWindowsTextureRegistrar::RegisterTexture(
if (texture_info->type == kFlutterDesktopPixelBufferTexture) { if (texture_info->type == kFlutterDesktopPixelBufferTexture) {
if (!texture_info->pixel_buffer_config.callback) { if (!texture_info->pixel_buffer_config.callback) {
std::cerr << "Invalid pixel buffer texture callback." << std::endl; FML_LOG(ERROR) << "Invalid pixel buffer texture callback.";
return kInvalidTexture; return kInvalidTexture;
} }
@@ -47,7 +47,7 @@ int64_t FlutterWindowsTextureRegistrar::RegisterTexture(
surface_type == kFlutterDesktopGpuSurfaceTypeD3d11Texture2D) { surface_type == kFlutterDesktopGpuSurfaceTypeD3d11Texture2D) {
auto callback = SAFE_ACCESS(gpu_surface_config, callback, nullptr); auto callback = SAFE_ACCESS(gpu_surface_config, callback, nullptr);
if (!callback) { if (!callback) {
std::cerr << "Invalid GPU surface descriptor callback." << std::endl; FML_LOG(ERROR) << "Invalid GPU surface descriptor callback.";
return kInvalidTexture; return kInvalidTexture;
} }
@@ -58,7 +58,7 @@ int64_t FlutterWindowsTextureRegistrar::RegisterTexture(
} }
} }
std::cerr << "Attempted to register texture of unsupport type." << std::endl; FML_LOG(ERROR) << "Attempted to register texture of unsupport type.";
return kInvalidTexture; return kInvalidTexture;
} }

View File

@@ -6,8 +6,7 @@
#include <windows.h> #include <windows.h>
#include <iostream> #include "flutter/fml/logging.h"
#include "flutter/shell/platform/common/json_message_codec.h" #include "flutter/shell/platform/common/json_message_codec.h"
#include "flutter/shell/platform/windows/keyboard_utils.h" #include "flutter/shell/platform/windows/keyboard_utils.h"
@@ -139,7 +138,7 @@ void KeyboardKeyChannelHandler::KeyboardHook(
event.AddMember(kTypeKey, kKeyUp, allocator); event.AddMember(kTypeKey, kKeyUp, allocator);
break; break;
default: default:
std::cerr << "Unknown key event action: " << action << std::endl; FML_LOG(WARNING) << "Unknown key event action: " << action;
callback(false); callback(false);
return; return;
} }

View File

@@ -6,8 +6,7 @@
#include <windows.h> #include <windows.h>
#include <iostream> #include "flutter/fml/logging.h"
#include "flutter/shell/platform/windows/keyboard_utils.h" #include "flutter/shell/platform/windows/keyboard_utils.h"
namespace flutter { namespace flutter {
@@ -48,10 +47,10 @@ void KeyboardKeyHandler::KeyboardHook(int key,
incoming->callback = std::move(callback); incoming->callback = std::move(callback);
if (pending_responds_.size() > kMaxPendingEvents) { if (pending_responds_.size() > kMaxPendingEvents) {
std::cerr FML_LOG(ERROR)
<< "There are " << pending_responds_.size() << "There are " << pending_responds_.size()
<< " keyboard events that have not yet received a response from the " << " keyboard events that have not yet received a response from the "
<< "framework. Are responses being sent?" << std::endl; << "framework. Are responses being sent?";
} }
pending_responds_.push_back(std::move(incoming)); pending_responds_.push_back(std::move(incoming));

View File

@@ -3,10 +3,10 @@
// found in the LICENSE file. // found in the LICENSE file.
#include <assert.h> #include <assert.h>
#include <iostream>
#include <memory> #include <memory>
#include <string> #include <string>
#include "flutter/fml/logging.h"
#include "flutter/shell/platform/windows/keyboard_manager.h" #include "flutter/shell/platform/windows/keyboard_manager.h"
#include "flutter/shell/platform/windows/keyboard_utils.h" #include "flutter/shell/platform/windows/keyboard_utils.h"
@@ -120,15 +120,14 @@ void KeyboardManager::RedispatchEvent(std::unique_ptr<PendingEvent> event) {
UINT result = window_delegate_->Win32DispatchMessage( UINT result = window_delegate_->Win32DispatchMessage(
message.action, message.wparam, message.lparam); message.action, message.wparam, message.lparam);
if (result != 0) { if (result != 0) {
std::cerr << "Unable to synthesize event for keyboard event." FML_LOG(ERROR) << "Unable to synthesize event for keyboard event.";
<< std::endl;
} }
} }
if (pending_redispatches_.size() > kMaxPendingEvents) { if (pending_redispatches_.size() > kMaxPendingEvents) {
std::cerr FML_LOG(ERROR)
<< "There are " << pending_redispatches_.size() << "There are " << pending_redispatches_.size()
<< " keyboard events that have not yet received a response from the " << " keyboard events that have not yet received a response from the "
<< "framework. Are responses being sent?" << std::endl; << "framework. Are responses being sent?";
} }
} }

View File

@@ -7,9 +7,9 @@
#include <windows.h> #include <windows.h>
#include <cstring> #include <cstring>
#include <iostream>
#include <optional> #include <optional>
#include "flutter/fml/logging.h"
#include "flutter/fml/platform/win/wstring_conversion.h" #include "flutter/fml/platform/win/wstring_conversion.h"
#include "flutter/shell/platform/common/json_method_codec.h" #include "flutter/shell/platform/common/json_method_codec.h"
#include "flutter/shell/platform/windows/flutter_windows_view.h" #include "flutter/shell/platform/windows/flutter_windows_view.h"
@@ -41,14 +41,16 @@ class ScopedGlobalMemory {
ScopedGlobalMemory(unsigned int flags, size_t bytes) { ScopedGlobalMemory(unsigned int flags, size_t bytes) {
memory_ = ::GlobalAlloc(flags, bytes); memory_ = ::GlobalAlloc(flags, bytes);
if (!memory_) { if (!memory_) {
std::cerr << "Unable to allocate global memory: " << ::GetLastError(); FML_LOG(ERROR) << "Unable to allocate global memory: "
<< ::GetLastError();
} }
} }
~ScopedGlobalMemory() { ~ScopedGlobalMemory() {
if (memory_) { if (memory_) {
if (::GlobalFree(memory_) != nullptr) { if (::GlobalFree(memory_) != nullptr) {
std::cerr << "Failed to free global allocation: " << ::GetLastError(); FML_LOG(ERROR) << "Failed to free global allocation: "
<< ::GetLastError();
} }
} }
} }
@@ -79,7 +81,7 @@ class ScopedGlobalLock {
if (memory) { if (memory) {
locked_memory_ = ::GlobalLock(memory); locked_memory_ = ::GlobalLock(memory);
if (!locked_memory_) { if (!locked_memory_) {
std::cerr << "Unable to acquire global lock: " << ::GetLastError(); FML_LOG(ERROR) << "Unable to acquire global lock: " << ::GetLastError();
} }
} }
} }
@@ -89,7 +91,8 @@ class ScopedGlobalLock {
if (!::GlobalUnlock(source_)) { if (!::GlobalUnlock(source_)) {
DWORD error = ::GetLastError(); DWORD error = ::GetLastError();
if (error != NO_ERROR) { if (error != NO_ERROR) {
std::cerr << "Unable to release global lock: " << ::GetLastError(); FML_LOG(ERROR) << "Unable to release global lock: "
<< ::GetLastError();
} }
} }
} }

View File

@@ -5,7 +5,8 @@
#include "flutter/shell/platform/windows/task_runner_window.h" #include "flutter/shell/platform/windows/task_runner_window.h"
#include <algorithm> #include <algorithm>
#include <iostream>
#include "flutter/fml/logging.h"
namespace flutter { namespace flutter {
@@ -52,7 +53,7 @@ std::shared_ptr<TaskRunnerWindow> TaskRunnerWindow::GetSharedInstance() {
void TaskRunnerWindow::WakeUp() { void TaskRunnerWindow::WakeUp() {
if (!PostMessage(window_handle_, WM_NULL, 0, 0)) { if (!PostMessage(window_handle_, WM_NULL, 0, 0)) {
std::cerr << "Failed to post message to main thread." << std::endl; FML_LOG(ERROR) << "Failed to post message to main thread.";
} }
} }