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

View File

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

View File

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

View File

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

View File

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

View File

@@ -4,9 +4,9 @@
#include "flutter/shell/platform/windows/flutter_windows_texture_registrar.h"
#include <iostream>
#include <mutex>
#include "flutter/fml/logging.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_pixelbuffer.h"
@@ -31,7 +31,7 @@ int64_t FlutterWindowsTextureRegistrar::RegisterTexture(
if (texture_info->type == kFlutterDesktopPixelBufferTexture) {
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;
}
@@ -47,7 +47,7 @@ int64_t FlutterWindowsTextureRegistrar::RegisterTexture(
surface_type == kFlutterDesktopGpuSurfaceTypeD3d11Texture2D) {
auto callback = SAFE_ACCESS(gpu_surface_config, callback, nullptr);
if (!callback) {
std::cerr << "Invalid GPU surface descriptor callback." << std::endl;
FML_LOG(ERROR) << "Invalid GPU surface descriptor callback.";
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;
}

View File

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

View File

@@ -6,8 +6,7 @@
#include <windows.h>
#include <iostream>
#include "flutter/fml/logging.h"
#include "flutter/shell/platform/windows/keyboard_utils.h"
namespace flutter {
@@ -48,10 +47,10 @@ void KeyboardKeyHandler::KeyboardHook(int key,
incoming->callback = std::move(callback);
if (pending_responds_.size() > kMaxPendingEvents) {
std::cerr
FML_LOG(ERROR)
<< "There are " << pending_responds_.size()
<< " 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));

View File

@@ -3,10 +3,10 @@
// found in the LICENSE file.
#include <assert.h>
#include <iostream>
#include <memory>
#include <string>
#include "flutter/fml/logging.h"
#include "flutter/shell/platform/windows/keyboard_manager.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(
message.action, message.wparam, message.lparam);
if (result != 0) {
std::cerr << "Unable to synthesize event for keyboard event."
<< std::endl;
FML_LOG(ERROR) << "Unable to synthesize event for keyboard event.";
}
}
if (pending_redispatches_.size() > kMaxPendingEvents) {
std::cerr
FML_LOG(ERROR)
<< "There are " << pending_redispatches_.size()
<< " 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 <cstring>
#include <iostream>
#include <optional>
#include "flutter/fml/logging.h"
#include "flutter/fml/platform/win/wstring_conversion.h"
#include "flutter/shell/platform/common/json_method_codec.h"
#include "flutter/shell/platform/windows/flutter_windows_view.h"
@@ -41,14 +41,16 @@ class ScopedGlobalMemory {
ScopedGlobalMemory(unsigned int flags, size_t bytes) {
memory_ = ::GlobalAlloc(flags, bytes);
if (!memory_) {
std::cerr << "Unable to allocate global memory: " << ::GetLastError();
FML_LOG(ERROR) << "Unable to allocate global memory: "
<< ::GetLastError();
}
}
~ScopedGlobalMemory() {
if (memory_) {
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) {
locked_memory_ = ::GlobalLock(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_)) {
DWORD error = ::GetLastError();
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 <algorithm>
#include <iostream>
#include "flutter/fml/logging.h"
namespace flutter {
@@ -52,7 +53,7 @@ std::shared_ptr<TaskRunnerWindow> TaskRunnerWindow::GetSharedInstance() {
void TaskRunnerWindow::WakeUp() {
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.";
}
}