From 710df81249922f6270a9ef078348d2492480794c Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Fri, 2 Jun 2017 09:32:08 -0700 Subject: [PATCH] Simplify log forwarding on iOS, Android (flutter/engine#3726) Eliminates logging to stdout on Android -- now using __android_log_print only. Eliminates logging to syslog on iOS -- now writing to stdout with the existing ASL redirection (from platform_mac.mm) only. syslog() wasn't ever picked up in logs. This patch is a pre-factoring change before swapping out iOS engine logging to a flutter-specific mechanism. --- .../src/flutter/lib/ui/dart_runtime_hooks.cc | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/engine/src/flutter/lib/ui/dart_runtime_hooks.cc b/engine/src/flutter/lib/ui/dart_runtime_hooks.cc index 57c9f9b659d..af4569af6ab 100644 --- a/engine/src/flutter/lib/ui/dart_runtime_hooks.cc +++ b/engine/src/flutter/lib/ui/dart_runtime_hooks.cc @@ -27,13 +27,6 @@ #include #endif -#if __APPLE__ -extern "C" { -// Cannot import the syslog.h header directly because of macro collision -extern void syslog(int, const char*, ...); -} -#endif - using tonic::LogIfError; using tonic::ToDart; @@ -146,18 +139,18 @@ void Logger_PrintString(Dart_NativeArguments args) { if (Dart_IsError(result)) { Dart_PropagateError(result); } else { - // Uses fwrite to support printing NUL bytes. - fwrite(chars, 1, length, stdout); - fputs("\n", stdout); - fflush(stdout); #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. + // Write to the logcat on Android. 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); + // Write directly to stdout on iOS, which is redirected to ASL via + // RedirectIOConnectionsToSyslog in platform_mac.mm. + // TODO(cbracken) replace with dedicated (non-stdout) logging. + fwrite(chars, 1, length, stdout); + fputs("\n", stdout); + fflush(stdout); #endif } if (dart::bin::ShouldCaptureStdout()) {