An API for setting the tag for Flutter log messages on Android (flutter/engine#3335)
Fixes https://github.com/flutter/flutter/issues/7226
This commit is contained in:
@@ -30,6 +30,7 @@ struct Settings {
|
||||
std::string application_library_path;
|
||||
std::string temp_directory_path;
|
||||
std::vector<std::string> dart_flags;
|
||||
std::string log_tag = "flutter";
|
||||
|
||||
static const Settings& Get();
|
||||
static void Set(const Settings& settings);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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<T> {
|
||||
static <T> ImmutableSetBuilder<T> 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;
|
||||
|
||||
Reference in New Issue
Block a user