diff --git a/engine/src/flutter/common/settings.h b/engine/src/flutter/common/settings.h index 00ac222d0b..48b9ed7003 100644 --- a/engine/src/flutter/common/settings.h +++ b/engine/src/flutter/common/settings.h @@ -30,6 +30,7 @@ struct Settings { std::string application_library_path; std::string temp_directory_path; std::vector dart_flags; + std::string log_tag = "flutter"; static const Settings& Get(); static void Set(const Settings& settings); diff --git a/engine/src/flutter/lib/ui/dart_runtime_hooks.cc b/engine/src/flutter/lib/ui/dart_runtime_hooks.cc index f02969d5a8..aa028ddb3e 100644 --- a/engine/src/flutter/lib/ui/dart_runtime_hooks.cc +++ b/engine/src/flutter/lib/ui/dart_runtime_hooks.cc @@ -11,6 +11,7 @@ #include "dart/runtime/bin/embedded_dart_io.h" #include "dart/runtime/include/dart_api.h" #include "dart/runtime/include/dart_tools_api.h" +#include "flutter/common/settings.h" #include "lib/ftl/build_config.h" #include "lib/ftl/logging.h" #include "lib/tonic/converter/dart_converter.h" @@ -152,7 +153,8 @@ void Logger_PrintString(Dart_NativeArguments args) { #if defined(OS_ANDROID) // In addition to writing to the stdout, write to the logcat so that the // message is discoverable when running on an unrooted device. - __android_log_print(ANDROID_LOG_INFO, "flutter", "%.*s", (int)length, + const char* tag = Settings::Get().log_tag.c_str(); + __android_log_print(ANDROID_LOG_INFO, tag, "%.*s", (int)length, chars); #elif __APPLE__ syslog(1 /* LOG_ALERT */, "%.*s", (int)length, chars); diff --git a/engine/src/flutter/shell/common/shell.cc b/engine/src/flutter/shell/common/shell.cc index cd9064a842..b60999b955 100644 --- a/engine/src/flutter/shell/common/shell.cc +++ b/engine/src/flutter/shell/common/shell.cc @@ -189,6 +189,11 @@ void Shell::InitStandalone(std::string icu_data_path, settings.dart_flags.push_back(*it); } + if (command_line.HasSwitch(FlagForSwitch(Switch::LogTag))) { + settings.log_tag = command_line.GetSwitchValueASCII( + FlagForSwitch(Switch::LogTag)); + } + blink::Settings::Set(settings); Init(); diff --git a/engine/src/flutter/shell/common/switches.h b/engine/src/flutter/shell/common/switches.h index 1a20987474..33692a5b1a 100644 --- a/engine/src/flutter/shell/common/switches.h +++ b/engine/src/flutter/shell/common/switches.h @@ -55,6 +55,7 @@ DEF_SWITCH(EndlessTraceBuffer, "indefinitely however.") DEF_SWITCH(FLX, "flx", "Specify the the FLX path.") DEF_SWITCH(Help, "help", "Display this help text.") +DEF_SWITCH(LogTag, "log-tag", "Tag associated with log messages.") DEF_SWITCH(MainDartFile, "dart-main", "The path to the main Dart file.") DEF_SWITCH(NonInteractive, "non-interactive", diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterMain.java b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterMain.java index ef28d0005b..d7e20ffe8b 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterMain.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterMain.java @@ -83,6 +83,7 @@ public class FlutterMain { private static boolean sInitialized = false; private static ResourceExtractor sResourceExtractor; private static boolean sIsPrecompiled; + private static Settings sSettings; private static final class ImmutableSetBuilder { static ImmutableSetBuilder newInstance() { @@ -111,10 +112,34 @@ public class FlutterMain { } } + public static class Settings { + private String logTag; + + public String getLogTag() { + return logTag; + } + + /** + * Set the tag associated with Flutter app log messages. + */ + public void setLogTag(String tag) { + logTag = tag; + } + } + /** * Starts initialization of the native system. */ public static void startInitialization(Context applicationContext) { + startInitialization(applicationContext, new Settings()); + } + + /** + * Starts initialization of the native system. + */ + public static void startInitialization(Context applicationContext, Settings settings) { + sSettings = settings; + long initStartTimestampMillis = SystemClock.uptimeMillis(); initConfig(applicationContext); initJavaUtils(applicationContext); @@ -157,6 +182,10 @@ public class FlutterMain { PathUtils.getCacheDirectory(applicationContext)); } + if (sSettings.getLogTag() != null) { + shellArgs.add("--log-tag=" + sSettings.getLogTag()); + } + nativeInit(applicationContext, shellArgs.toArray(new String[0])); sInitialized = true;