From 513442af27efa998638434e45261bb97ab08a429 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 1 Jun 2017 16:34:36 -0700 Subject: [PATCH] Simplify log forwarding on iOS, Android 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. --- lib/ui/dart_runtime_hooks.cc | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/lib/ui/dart_runtime_hooks.cc b/lib/ui/dart_runtime_hooks.cc index 57c9f9b659dd0..af4569af6aba4 100644 --- a/lib/ui/dart_runtime_hooks.cc +++ b/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()) {