Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,9 @@ FlutterEngineResult FlutterEngineInitialize(size_t version,
callback(tag.c_str(), message.c_str(), user_data);
};
}
if (SAFE_ACCESS(args, log_tag, nullptr) != nullptr) {
settings.log_tag = SAFE_ACCESS(args, log_tag, nullptr);
}

flutter::PlatformViewEmbedder::UpdateSemanticsNodesCallback
update_semantics_nodes_callback = nullptr;
Expand Down
7 changes: 7 additions & 0 deletions shell/platform/embedder/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,13 @@ typedef struct {
// thread and embedders must re-thread if necessary. Performing blocking calls
// in this callback may introduce application jank.
FlutterLogMessageCallback log_message_callback;

// A tag string associated with application log messages.
//
// A log message tag string that can be used convey application, subsystem,
// or component name to embedder's logger. This string will be passed to to
// callbacks on `log_message_callback`. Defaults to "flutter" if unspecified.
const char* log_tag;
} FlutterProjectArgs;

#ifndef FLUTTER_ENGINE_NO_PROTOTYPES
Expand Down
5 changes: 5 additions & 0 deletions shell/platform/embedder/tests/embedder_config_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ void EmbedderConfigBuilder::SetLogMessageCallbackHook() {
EmbedderTestContext::GetLogMessageCallbackHook();
}

void EmbedderConfigBuilder::SetLogTag(std::string tag) {
log_tag_ = std::move(tag);
project_args_.log_tag = log_tag_.c_str();
}

void EmbedderConfigBuilder::SetLocalizationCallbackHooks() {
project_args_.compute_platform_resolved_locale_callback =
EmbedderTestContext::GetComputePlatformResolvedLocaleCallbackHook();
Expand Down
5 changes: 5 additions & 0 deletions shell/platform/embedder/tests/embedder_config_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ class EmbedderConfigBuilder {

void SetSemanticsCallbackHooks();

// Used to set a custom log message handler.
void SetLogMessageCallbackHook();

// Used to set a custom log tag.
void SetLogTag(std::string tag);

void SetLocalizationCallbackHooks();

void SetDartEntrypoint(std::string entrypoint);
Expand Down Expand Up @@ -117,6 +121,7 @@ class EmbedderConfigBuilder {
FlutterCompositor compositor_ = {};
std::vector<std::string> command_line_arguments_;
std::vector<std::string> dart_entrypoint_arguments_;
std::string log_tag_;

UniqueEngine SetupEngine(bool run) const;

Expand Down
23 changes: 22 additions & 1 deletion shell/platform/embedder/tests/embedder_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@ TEST_F(EmbedderTest, InvalidPlatformMessages) {
}

//------------------------------------------------------------------------------
/// Tests that setting a custom log callback works as expected.
/// Tests that setting a custom log callback works as expected and defaults to
/// using tag "flutter".
TEST_F(EmbedderTest, CanSetCustomLogMessageCallback) {
fml::AutoResetWaitableEvent callback_latch;
auto& context = GetEmbedderContext(EmbedderTestContextType::kSoftwareContext);
Expand All @@ -471,6 +472,26 @@ TEST_F(EmbedderTest, CanSetCustomLogMessageCallback) {
callback_latch.Wait();
}

//------------------------------------------------------------------------------
/// Tests that setting a custom log tag works.
TEST_F(EmbedderTest, CanSetCustomLogTag) {
fml::AutoResetWaitableEvent callback_latch;
auto& context = GetEmbedderContext(EmbedderTestContextType::kSoftwareContext);
EmbedderConfigBuilder builder(context);
builder.SetDartEntrypoint("custom_logger");
builder.SetSoftwareRendererConfig();
builder.SetLogTag("butterfly");
context.SetLogMessageCallback(
[&callback_latch](const char* tag, const char* message) {
EXPECT_EQ(std::string(tag), "butterfly");
EXPECT_EQ(std::string(message), "hello world");
callback_latch.Signal();
});
auto engine = builder.LaunchEngine();
ASSERT_TRUE(engine.is_valid());
callback_latch.Wait();
}

//------------------------------------------------------------------------------
/// Asserts behavior of FlutterProjectArgs::shutdown_dart_vm_when_done (which is
/// set to true by default in these unit-tests).
Expand Down