Skip to content

Commit 1031d2c

Browse files
kenrussellCommit Bot
authored andcommitted
Upstream Mac logging changes from WebKit.
Use os_log_with_type in ANGLE's logging facility rather than fprintf. Bug: angleproject:4263 Change-Id: I0c418fc5544001bf4f47ff511d05de2f0ebaa1de Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1987145 Reviewed-by: Kai Ninomiya <kainino@chromium.org> Reviewed-by: James Darpinian <jdarpinian@chromium.org> Commit-Queue: Kenneth Russell <kbr@chromium.org>
1 parent 81ee4d2 commit 1031d2c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/common/debug.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
# include <android/log.h>
2222
#endif
2323

24+
#if defined(ANGLE_PLATFORM_APPLE)
25+
# include <os/log.h>
26+
#endif
27+
2428
#include "anglebase/no_destructor.h"
2529
#include "common/Optional.h"
2630
#include "common/angleutils.h"
@@ -228,6 +232,30 @@ void Trace(LogSeverity severity, const char *message)
228232
}
229233
__android_log_print(android_priority, "ANGLE", "%s: %s\n", LogSeverityName(severity),
230234
str.c_str());
235+
#elif defined(ANGLE_PLATFORM_APPLE)
236+
if (__builtin_available(macOS 10.12, iOS 10.0, *))
237+
{
238+
os_log_type_t apple_log_type = OS_LOG_TYPE_DEFAULT;
239+
switch (severity)
240+
{
241+
case LOG_INFO:
242+
apple_log_type = OS_LOG_TYPE_INFO;
243+
break;
244+
case LOG_WARN:
245+
apple_log_type = OS_LOG_TYPE_DEFAULT;
246+
break;
247+
case LOG_ERR:
248+
apple_log_type = OS_LOG_TYPE_ERROR;
249+
break;
250+
case LOG_FATAL:
251+
// OS_LOG_TYPE_FAULT is too severe - grabs the entire process tree.
252+
apple_log_type = OS_LOG_TYPE_ERROR;
253+
break;
254+
default:
255+
UNREACHABLE();
256+
}
257+
os_log_with_type(OS_LOG_DEFAULT, apple_log_type, "ANGLE: %s: %s\n", LogSeverityName(severity), str.c_str());
258+
}
231259
#else
232260
// Note: we use fprintf because <iostream> includes static initializers.
233261
fprintf((severity >= LOG_ERR) ? stderr : stdout, "%s: %s\n", LogSeverityName(severity),

0 commit comments

Comments
 (0)