提交 25c7a86a 编写于 作者: C Chris Bracken 提交者: GitHub

Eliminate ASL stdout forwarding on iOS (#3797)

ASL was deprecated in iOS 10 and started causing SIGPIPE issues in iOS
10.3. Under the iOS 8 SDK, syslog() stopped working as of iOS 10.3
devices, with the result that ASL stdout/stderr forwarding was the only
means of logging. The engine now builds against the iOS 10 SDK, with
deployment target of iOS 8. Under this SDK, syslog() works correctly
across all supported OS versions.

NOTE: This is a temporary fix to get developers unblocked. While this
does fix the SIGPIPE issue and put iOS logging on par with the Android
solution, the intent is to move to a dedicated communication channel
with flutter_tools that isn't log-based.
上级 d8ac43c3
...@@ -25,6 +25,11 @@ ...@@ -25,6 +25,11 @@
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include <android/log.h> #include <android/log.h>
#elif defined(OS_IOS)
extern "C" {
// Cannot import the syslog.h header directly because of macro collision.
extern void syslog(int, const char*, ...);
}
#endif #endif
using tonic::LogIfError; using tonic::LogIfError;
...@@ -143,11 +148,15 @@ void Logger_PrintString(Dart_NativeArguments args) { ...@@ -143,11 +148,15 @@ void Logger_PrintString(Dart_NativeArguments args) {
// Write to the logcat on Android. // Write to the logcat on Android.
const char* tag = Settings::Get().log_tag.c_str(); const char* tag = Settings::Get().log_tag.c_str();
__android_log_print(ANDROID_LOG_INFO, tag, "%.*s", (int)length, chars); __android_log_print(ANDROID_LOG_INFO, tag, "%.*s", (int)length, chars);
#elif defined(OS_IOS)
// Write to syslog on iOS.
//
// TODO(cbracken): replace with dedicated communication channel and bypass
// iOS logging APIs altogether.
syslog(1 /* LOG_ALERT */, "%.*s", (int)length, chars);
#else #else
// On Fuchsia, iOS and in flutter_tester (on both macOS and Linux), write // On Fuchsia and in flutter_tester (on both macOS and Linux), write
// directly to stdout. On iOS, this is redirected to ASL via // directly to stdout.
// RedirectIOConnectionsToSyslog in platform_mac.mm.
// TODO(cbracken): replace with dedicated (non-stdout) logging on iOS.
fwrite(chars, 1, length, stdout); fwrite(chars, 1, length, stdout);
fputs("\n", stdout); fputs("\n", stdout);
fflush(stdout); fflush(stdout);
......
...@@ -74,11 +74,6 @@ DEF_SWITCH(NonInteractive, ...@@ -74,11 +74,6 @@ DEF_SWITCH(NonInteractive,
"non-interactive", "non-interactive",
"Make the shell non-interactive. By default, the shell attempts " "Make the shell non-interactive. By default, the shell attempts "
"to setup a window and create an OpenGL context.") "to setup a window and create an OpenGL context.")
DEF_SWITCH(NoRedirectToSyslog,
"no-redirect-to-syslog",
"On iOS: Don't redirect stdout and stderr to syslog by default. "
"This is used by the tools to read device logs. However, this can "
"cause logs to not show up when launched from Xcode.")
DEF_SWITCH(Packages, "packages", "Specify the path to the packages.") DEF_SWITCH(Packages, "packages", "Specify the path to the packages.")
DEF_SWITCH(StartPaused, DEF_SWITCH(StartPaused,
"start-paused", "start-paused",
......
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
#include <Foundation/Foundation.h> #include <Foundation/Foundation.h>
#include <asl.h>
#include "dart/runtime/include/dart_tools_api.h" #include "dart/runtime/include/dart_tools_api.h"
#include "flutter/common/threads.h" #include "flutter/common/threads.h"
#include "flutter/fml/trace_event.h" #include "flutter/fml/trace_event.h"
...@@ -20,17 +18,6 @@ ...@@ -20,17 +18,6 @@
namespace shell { namespace shell {
static void RedirectIOConnectionsToSyslog(const ftl::CommandLine& command_line) {
#if TARGET_OS_IPHONE
if (command_line.HasOption(FlagForSwitch(Switch::NoRedirectToSyslog))) {
return;
}
asl_log_descriptor(NULL, NULL, ASL_LEVEL_NOTICE, STDOUT_FILENO, ASL_LOG_DESCRIPTOR_WRITE);
asl_log_descriptor(NULL, NULL, ASL_LEVEL_WARNING, STDERR_FILENO, ASL_LOG_DESCRIPTOR_WRITE);
#endif
}
static ftl::CommandLine InitializedCommandLine() { static ftl::CommandLine InitializedCommandLine() {
std::vector<std::string> args_vector; std::vector<std::string> args_vector;
...@@ -54,8 +41,6 @@ class EmbedderState { ...@@ -54,8 +41,6 @@ class EmbedderState {
auto command_line = InitializedCommandLine(); auto command_line = InitializedCommandLine();
RedirectIOConnectionsToSyslog(command_line);
// This is about as early as tracing of any kind can start. Add an instant // This is about as early as tracing of any kind can start. Add an instant
// marker that can be used as a reference for startup. // marker that can be used as a reference for startup.
TRACE_EVENT_INSTANT0("flutter", "main"); TRACE_EVENT_INSTANT0("flutter", "main");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册