diff --git a/lib/ui/dart_runtime_hooks.cc b/lib/ui/dart_runtime_hooks.cc index aa028ddb3e7d29364c1eb699dcc9f037789f3a2e..1b43c88aa99907ba7b57e1111c2a03f01dbd9248 100644 --- a/lib/ui/dart_runtime_hooks.cc +++ b/lib/ui/dart_runtime_hooks.cc @@ -28,10 +28,7 @@ #endif #if __APPLE__ -extern "C" { -// Cannot import the syslog.h header directly because of macro collision -extern void syslog(int, const char*, ...); -} +#include #endif using tonic::LogIfError; @@ -157,7 +154,7 @@ void Logger_PrintString(Dart_NativeArguments args) { __android_log_print(ANDROID_LOG_INFO, tag, "%.*s", (int)length, chars); #elif __APPLE__ - syslog(1 /* LOG_ALERT */, "%.*s", (int)length, chars); + asl_log_message(ASL_LEVEL_NOTICE, "%.*s", (int)length, chars); #endif } if (dart::bin::ShouldCaptureStdout()) { diff --git a/shell/common/switches.h b/shell/common/switches.h index 8913dbb54719b293a92919b171b8e1f8e5cfeded..4ced30821c82a9c14dcb08dd913d7c0b36bda889 100644 --- a/shell/common/switches.h +++ b/shell/common/switches.h @@ -62,6 +62,11 @@ DEF_SWITCH(NonInteractive, "non-interactive", "Make the shell non-interactive. By default, the shell attempts " "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(StartPaused, "start-paused", diff --git a/shell/platform/darwin/common/platform_mac.mm b/shell/platform/darwin/common/platform_mac.mm index ce4420a78ea224cfc9edf8731b6ff4e7ac3fd27c..ddd188d5b30d1174c893bfb4cb914973b2ce2e1a 100644 --- a/shell/platform/darwin/common/platform_mac.mm +++ b/shell/platform/darwin/common/platform_mac.mm @@ -36,6 +36,20 @@ static void InitializeLogging() { false); // Tick count } +static void RedirectIOConnectionsToSyslog() { +#if TARGET_OS_IPHONE + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + 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 void InitializeCommandLine() { base::mac::ScopedNSAutoreleasePool pool; base::CommandLine::StringVector vector; @@ -63,6 +77,8 @@ class EmbedderState { InitializeCommandLine(); + RedirectIOConnectionsToSyslog(); + InitializeLogging(); base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();