Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cd1a1cb

Browse files
authored
[Windows] Migrate error logging to FML_LOG (#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).
1 parent 2180e62 commit cd1a1cb

11 files changed

+66
-64
lines changed

shell/platform/windows/angle_surface_manager.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
#include "flutter/shell/platform/windows/angle_surface_manager.h"
66

7-
#include <iostream>
87
#include <vector>
98

9+
#include "flutter/fml/logging.h"
10+
1011
// Logs an EGL error to stderr. This automatically calls eglGetError()
1112
// and logs the error code.
1213
static void LogEglError(std::string message) {
1314
EGLint error = eglGetError();
14-
std::cerr << "EGL: " << message << std::endl;
15-
std::cerr << "EGL: eglGetError returned " << error << std::endl;
15+
FML_LOG(ERROR) << "EGL: " << message;
16+
FML_LOG(ERROR) << "EGL: eglGetError returned " << error;
1617
}
1718

1819
namespace flutter {
@@ -245,8 +246,8 @@ void AngleSurfaceManager::ResizeSurface(WindowsRenderTarget* render_target,
245246
ClearContext();
246247
DestroySurface();
247248
if (!CreateSurface(render_target, width, height)) {
248-
std::cerr << "AngleSurfaceManager::ResizeSurface failed to create surface"
249-
<< std::endl;
249+
FML_LOG(ERROR)
250+
<< "AngleSurfaceManager::ResizeSurface failed to create surface";
250251
}
251252
}
252253
}

shell/platform/windows/external_texture_d3d.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
#include <EGL/egl.h>
88
#include <EGL/eglext.h>
9-
#include <iostream>
109

10+
#include "flutter/fml/logging.h"
1111
#include "flutter/shell/platform/embedder/embedder_struct_macros.h"
1212

1313
namespace flutter {
@@ -107,7 +107,7 @@ bool ExternalTextureD3d::CreateOrUpdateTexture(
107107
if (egl_surface_ == EGL_NO_SURFACE ||
108108
eglBindTexImage(surface_manager_->egl_display(), egl_surface_,
109109
EGL_BACK_BUFFER) == EGL_FALSE) {
110-
std::cerr << "Binding D3D surface failed." << std::endl;
110+
FML_LOG(ERROR) << "Binding D3D surface failed.";
111111
}
112112
last_surface_handle_ = handle;
113113
}

shell/platform/windows/flutter_project_bundle.cc

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include "flutter/shell/platform/windows/flutter_project_bundle.h"
66

77
#include <filesystem>
8-
#include <iostream>
98

9+
#include "flutter/fml/logging.h"
1010
#include "flutter/shell/platform/common/engine_switches.h" // nogncheck
1111
#include "flutter/shell/platform/common/path_utils.h"
1212

@@ -34,9 +34,8 @@ FlutterProjectBundle::FlutterProjectBundle(
3434
(!aot_library_path_.empty() && aot_library_path_.is_relative())) {
3535
std::filesystem::path executable_location = GetExecutableDirectory();
3636
if (executable_location.empty()) {
37-
std::cerr
38-
<< "Unable to find executable location to resolve resource paths."
39-
<< std::endl;
37+
FML_LOG(ERROR)
38+
<< "Unable to find executable location to resolve resource paths.";
4039
assets_path_ = std::filesystem::path();
4140
icu_path_ = std::filesystem::path();
4241
} else {
@@ -59,14 +58,13 @@ bool FlutterProjectBundle::HasValidPaths() {
5958
UniqueAotDataPtr FlutterProjectBundle::LoadAotData(
6059
const FlutterEngineProcTable& engine_procs) {
6160
if (aot_library_path_.empty()) {
62-
std::cerr
63-
<< "Attempted to load AOT data, but no aot_library_path was provided."
64-
<< std::endl;
61+
FML_LOG(ERROR)
62+
<< "Attempted to load AOT data, but no aot_library_path was provided.";
6563
return UniqueAotDataPtr(nullptr, nullptr);
6664
}
6765
if (!std::filesystem::exists(aot_library_path_)) {
68-
std::cerr << "Can't load AOT data from " << aot_library_path_.u8string()
69-
<< "; no such file." << std::endl;
66+
FML_LOG(ERROR) << "Can't load AOT data from "
67+
<< aot_library_path_.u8string() << "; no such file.";
7068
return UniqueAotDataPtr(nullptr, nullptr);
7169
}
7270
std::string path_string = aot_library_path_.u8string();
@@ -76,7 +74,7 @@ UniqueAotDataPtr FlutterProjectBundle::LoadAotData(
7674
FlutterEngineAOTData data = nullptr;
7775
auto result = engine_procs.CreateAOTData(&source, &data);
7876
if (result != kSuccess) {
79-
std::cerr << "Failed to load AOT data from: " << path_string << std::endl;
77+
FML_LOG(ERROR) << "Failed to load AOT data from: " << path_string;
8078
return UniqueAotDataPtr(nullptr, nullptr);
8179
}
8280
return UniqueAotDataPtr(data, engine_procs.CollectAOTData);

shell/platform/windows/flutter_window.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <chrono>
99
#include <map>
1010

11+
#include "flutter/fml/logging.h"
12+
1113
namespace flutter {
1214

1315
namespace {
@@ -121,7 +123,7 @@ static uint64_t ConvertWinButtonToFlutterButton(UINT button) {
121123
case XBUTTON2:
122124
return kFlutterPointerButtonMouseForward;
123125
}
124-
std::cerr << "Mouse button not recognized: " << button << std::endl;
126+
FML_LOG(WARNING) << "Mouse button not recognized: " << button;
125127
return 0;
126128
}
127129

shell/platform/windows/flutter_windows_engine.cc

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <iostream>
1111
#include <sstream>
1212

13+
#include "flutter/fml/logging.h"
1314
#include "flutter/fml/platform/win/wstring_conversion.h"
1415
#include "flutter/shell/platform/common/client_wrapper/binary_messenger_impl.h"
1516
#include "flutter/shell/platform/common/path_utils.h"
@@ -156,17 +157,18 @@ FlutterWindowsEngine::FlutterWindowsEngine(const FlutterProjectBundle& project)
156157
embedder_api_.struct_size = sizeof(FlutterEngineProcTable);
157158
FlutterEngineGetProcAddresses(&embedder_api_);
158159

159-
task_runner_ = std::make_unique<TaskRunner>(
160-
embedder_api_.GetCurrentTime, [this](const auto* task) {
161-
if (!engine_) {
162-
std::cerr << "Cannot post an engine task when engine is not running."
163-
<< std::endl;
164-
return;
165-
}
166-
if (embedder_api_.RunTask(engine_, task) != kSuccess) {
167-
std::cerr << "Failed to post an engine task." << std::endl;
168-
}
169-
});
160+
task_runner_ =
161+
std::make_unique<TaskRunner>(
162+
embedder_api_.GetCurrentTime, [this](const auto* task) {
163+
if (!engine_) {
164+
FML_LOG(ERROR)
165+
<< "Cannot post an engine task when engine is not running.";
166+
return;
167+
}
168+
if (embedder_api_.RunTask(engine_, task) != kSuccess) {
169+
FML_LOG(ERROR) << "Failed to post an engine task.";
170+
}
171+
});
170172

171173
// Set up the legacy structs backing the API handles.
172174
messenger_ = std::make_unique<FlutterDesktopMessenger>();
@@ -206,15 +208,15 @@ bool FlutterWindowsEngine::Run() {
206208

207209
bool FlutterWindowsEngine::Run(std::string_view entrypoint) {
208210
if (!project_->HasValidPaths()) {
209-
std::cerr << "Missing or unresolvable paths to assets." << std::endl;
211+
FML_LOG(ERROR) << "Missing or unresolvable paths to assets.";
210212
return false;
211213
}
212214
std::string assets_path_string = project_->assets_path().u8string();
213215
std::string icu_path_string = project_->icu_path().u8string();
214216
if (embedder_api_.RunsAOTCompiledDartCode()) {
215217
aot_data_ = project_->LoadAotData(embedder_api_);
216218
if (!aot_data_) {
217-
std::cerr << "Unable to start engine without AOT data." << std::endl;
219+
FML_LOG(ERROR) << "Unable to start engine without AOT data.";
218220
return false;
219221
}
220222
}
@@ -272,10 +274,9 @@ bool FlutterWindowsEngine::Run(std::string_view entrypoint) {
272274
// method and only the entrypoint specified in project_ should be used.
273275
if (!project_->dart_entrypoint().empty() && !entrypoint.empty() &&
274276
project_->dart_entrypoint() != entrypoint) {
275-
std::cerr << "Conflicting entrypoints were specified in "
276-
"FlutterDesktopEngineProperties.dart_entrypoint and "
277-
"FlutterDesktopEngineRun(engine, entry_point). "
278-
<< std::endl;
277+
FML_LOG(ERROR) << "Conflicting entrypoints were specified in "
278+
"FlutterDesktopEngineProperties.dart_entrypoint and "
279+
"FlutterDesktopEngineRun(engine, entry_point). ";
279280
return false;
280281
}
281282
if (!entrypoint.empty()) {
@@ -339,8 +340,7 @@ bool FlutterWindowsEngine::Run(std::string_view entrypoint) {
339340
auto result = embedder_api_.Run(FLUTTER_ENGINE_VERSION, &renderer_config,
340341
&args, this, &engine_);
341342
if (result != kSuccess || engine_ == nullptr) {
342-
std::cerr << "Failed to start Flutter engine: error " << result
343-
<< std::endl;
343+
FML_LOG(ERROR) << "Failed to start Flutter engine: error " << result;
344344
return false;
345345
}
346346

@@ -454,7 +454,7 @@ bool FlutterWindowsEngine::SendPlatformMessage(
454454
embedder_api_.PlatformMessageCreateResponseHandle(
455455
engine_, reply, user_data, &response_handle);
456456
if (result != kSuccess) {
457-
std::cout << "Failed to create response handle\n";
457+
FML_LOG(ERROR) << "Failed to create response handle";
458458
return false;
459459
}
460460
}
@@ -486,9 +486,9 @@ void FlutterWindowsEngine::SendPlatformMessageResponse(
486486
void FlutterWindowsEngine::HandlePlatformMessage(
487487
const FlutterPlatformMessage* engine_message) {
488488
if (engine_message->struct_size != sizeof(FlutterPlatformMessage)) {
489-
std::cerr << "Invalid message size received. Expected: "
490-
<< sizeof(FlutterPlatformMessage) << " but received "
491-
<< engine_message->struct_size << std::endl;
489+
FML_LOG(ERROR) << "Invalid message size received. Expected: "
490+
<< sizeof(FlutterPlatformMessage) << " but received "
491+
<< engine_message->struct_size;
492492
return;
493493
}
494494

shell/platform/windows/flutter_windows_texture_registrar.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
#include "flutter/shell/platform/windows/flutter_windows_texture_registrar.h"
66

7-
#include <iostream>
87
#include <mutex>
98

9+
#include "flutter/fml/logging.h"
1010
#include "flutter/shell/platform/embedder/embedder_struct_macros.h"
1111
#include "flutter/shell/platform/windows/external_texture_d3d.h"
1212
#include "flutter/shell/platform/windows/external_texture_pixelbuffer.h"
@@ -31,7 +31,7 @@ int64_t FlutterWindowsTextureRegistrar::RegisterTexture(
3131

3232
if (texture_info->type == kFlutterDesktopPixelBufferTexture) {
3333
if (!texture_info->pixel_buffer_config.callback) {
34-
std::cerr << "Invalid pixel buffer texture callback." << std::endl;
34+
FML_LOG(ERROR) << "Invalid pixel buffer texture callback.";
3535
return kInvalidTexture;
3636
}
3737

@@ -47,7 +47,7 @@ int64_t FlutterWindowsTextureRegistrar::RegisterTexture(
4747
surface_type == kFlutterDesktopGpuSurfaceTypeD3d11Texture2D) {
4848
auto callback = SAFE_ACCESS(gpu_surface_config, callback, nullptr);
4949
if (!callback) {
50-
std::cerr << "Invalid GPU surface descriptor callback." << std::endl;
50+
FML_LOG(ERROR) << "Invalid GPU surface descriptor callback.";
5151
return kInvalidTexture;
5252
}
5353

@@ -58,7 +58,7 @@ int64_t FlutterWindowsTextureRegistrar::RegisterTexture(
5858
}
5959
}
6060

61-
std::cerr << "Attempted to register texture of unsupport type." << std::endl;
61+
FML_LOG(ERROR) << "Attempted to register texture of unsupport type.";
6262
return kInvalidTexture;
6363
}
6464

shell/platform/windows/keyboard_key_channel_handler.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
#include <windows.h>
88

9-
#include <iostream>
10-
9+
#include "flutter/fml/logging.h"
1110
#include "flutter/shell/platform/common/json_message_codec.h"
1211
#include "flutter/shell/platform/windows/keyboard_utils.h"
1312

@@ -139,7 +138,7 @@ void KeyboardKeyChannelHandler::KeyboardHook(
139138
event.AddMember(kTypeKey, kKeyUp, allocator);
140139
break;
141140
default:
142-
std::cerr << "Unknown key event action: " << action << std::endl;
141+
FML_LOG(WARNING) << "Unknown key event action: " << action;
143142
callback(false);
144143
return;
145144
}

shell/platform/windows/keyboard_key_handler.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
#include <windows.h>
88

9-
#include <iostream>
10-
9+
#include "flutter/fml/logging.h"
1110
#include "flutter/shell/platform/windows/keyboard_utils.h"
1211

1312
namespace flutter {
@@ -48,10 +47,10 @@ void KeyboardKeyHandler::KeyboardHook(int key,
4847
incoming->callback = std::move(callback);
4948

5049
if (pending_responds_.size() > kMaxPendingEvents) {
51-
std::cerr
50+
FML_LOG(ERROR)
5251
<< "There are " << pending_responds_.size()
5352
<< " keyboard events that have not yet received a response from the "
54-
<< "framework. Are responses being sent?" << std::endl;
53+
<< "framework. Are responses being sent?";
5554
}
5655
pending_responds_.push_back(std::move(incoming));
5756

shell/platform/windows/keyboard_manager.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
// found in the LICENSE file.
44

55
#include <assert.h>
6-
#include <iostream>
76
#include <memory>
87
#include <string>
98

9+
#include "flutter/fml/logging.h"
1010
#include "flutter/shell/platform/windows/keyboard_manager.h"
1111
#include "flutter/shell/platform/windows/keyboard_utils.h"
1212

@@ -120,15 +120,14 @@ void KeyboardManager::RedispatchEvent(std::unique_ptr<PendingEvent> event) {
120120
UINT result = window_delegate_->Win32DispatchMessage(
121121
message.action, message.wparam, message.lparam);
122122
if (result != 0) {
123-
std::cerr << "Unable to synthesize event for keyboard event."
124-
<< std::endl;
123+
FML_LOG(ERROR) << "Unable to synthesize event for keyboard event.";
125124
}
126125
}
127126
if (pending_redispatches_.size() > kMaxPendingEvents) {
128-
std::cerr
127+
FML_LOG(ERROR)
129128
<< "There are " << pending_redispatches_.size()
130129
<< " keyboard events that have not yet received a response from the "
131-
<< "framework. Are responses being sent?" << std::endl;
130+
<< "framework. Are responses being sent?";
132131
}
133132
}
134133

shell/platform/windows/platform_handler.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
#include <windows.h>
88

99
#include <cstring>
10-
#include <iostream>
1110
#include <optional>
1211

12+
#include "flutter/fml/logging.h"
1313
#include "flutter/fml/platform/win/wstring_conversion.h"
1414
#include "flutter/shell/platform/common/json_method_codec.h"
1515
#include "flutter/shell/platform/windows/flutter_windows_view.h"
@@ -41,14 +41,16 @@ class ScopedGlobalMemory {
4141
ScopedGlobalMemory(unsigned int flags, size_t bytes) {
4242
memory_ = ::GlobalAlloc(flags, bytes);
4343
if (!memory_) {
44-
std::cerr << "Unable to allocate global memory: " << ::GetLastError();
44+
FML_LOG(ERROR) << "Unable to allocate global memory: "
45+
<< ::GetLastError();
4546
}
4647
}
4748

4849
~ScopedGlobalMemory() {
4950
if (memory_) {
5051
if (::GlobalFree(memory_) != nullptr) {
51-
std::cerr << "Failed to free global allocation: " << ::GetLastError();
52+
FML_LOG(ERROR) << "Failed to free global allocation: "
53+
<< ::GetLastError();
5254
}
5355
}
5456
}
@@ -79,7 +81,7 @@ class ScopedGlobalLock {
7981
if (memory) {
8082
locked_memory_ = ::GlobalLock(memory);
8183
if (!locked_memory_) {
82-
std::cerr << "Unable to acquire global lock: " << ::GetLastError();
84+
FML_LOG(ERROR) << "Unable to acquire global lock: " << ::GetLastError();
8385
}
8486
}
8587
}
@@ -89,7 +91,8 @@ class ScopedGlobalLock {
8991
if (!::GlobalUnlock(source_)) {
9092
DWORD error = ::GetLastError();
9193
if (error != NO_ERROR) {
92-
std::cerr << "Unable to release global lock: " << ::GetLastError();
94+
FML_LOG(ERROR) << "Unable to release global lock: "
95+
<< ::GetLastError();
9396
}
9497
}
9598
}

0 commit comments

Comments
 (0)