|
30 | 30 |
|
31 | 31 | #if defined(OS_ANDROID) |
32 | 32 | #include <android/log.h> |
33 | | -#elif defined(OS_IOS) |
| 33 | +#elif defined(OS_MACOSX) |
| 34 | +#include <os/log.h> |
34 | 35 | extern "C" { |
35 | 36 | // Cannot import the syslog.h header directly because of macro collision. |
36 | 37 | extern void syslog(int, const char*, ...); |
@@ -199,19 +200,29 @@ void Logger_PrintString(Dart_NativeArguments args) { |
199 | 200 | // Write to the logcat on Android. |
200 | 201 | __android_log_print(ANDROID_LOG_INFO, logger_prefix.c_str(), "%.*s", |
201 | 202 | (int)length, chars); |
202 | | -#elif defined(OS_IOS) |
203 | | - // Write to syslog on iOS. |
204 | | - // |
| 203 | +#elif defined(OS_MACOSX) |
205 | 204 | // TODO(cbracken): replace with dedicated communication channel and bypass |
206 | 205 | // iOS logging APIs altogether. |
207 | | - syslog(1 /* LOG_ALERT */, "%.*s", (int)length, chars); |
| 206 | + // |
| 207 | + // Unified logging (os_log) became available in iOS 9.0 and syslog stopped |
| 208 | + // working in iOS 13.0. idevicesyslog made device syslog available on the |
| 209 | + // connected host, but there is no known API to view device unified logging |
| 210 | + // on the host. Flutter tool will continue to observe syslog on devices |
| 211 | + // older than iOS 13.0 since it provides more logging context, particularly |
| 212 | + // for application crashes. |
| 213 | + if (__builtin_available(iOS 13.0, macOS 10.11, *)) { |
| 214 | + os_log_t dart_log = os_log_create("io.flutter", "dart"); |
| 215 | + os_log(dart_log, "%.*s", static_cast<int>(length), chars); |
| 216 | + } else { |
| 217 | + syslog(1 /* LOG_ALERT */, "%.*s", @(length).intValue, chars); |
| 218 | + } |
208 | 219 | #else |
209 | 220 | std::cout << log_string << std::endl; |
210 | 221 | #endif |
211 | 222 | } |
212 | 223 |
|
213 | 224 | if (dart::bin::ShouldCaptureStdout()) { |
214 | | - // For now we report print output on the Stdout stream. |
| 225 | + // Report print output on the Stdout stream. |
215 | 226 | uint8_t newline[] = {'\n'}; |
216 | 227 | Dart_ServiceSendDataEvent("Stdout", "WriteEvent", |
217 | 228 | reinterpret_cast<const uint8_t*>(chars), length); |
|
0 commit comments