Move YGLogger into YGConfig and associate YGNodeRef with log events

Summary:
Moves the `YGLogger` into `YGConfig` and pass the `YGNodeRef` into the logger to be able to associate the log messages and assertions with the specific node.

Tackles facebook/yoga#530 and facebook/yoga#446
Closes https://github.com/facebook/yoga/pull/531

Reviewed By: astreet

Differential Revision: D4970149

Pulled By: emilsjolander

fbshipit-source-id: b7fcdaa273143ea2fa35861620b2e4d79f04f0af
This commit is contained in:
Lukas Wöhrl
2017-05-03 09:22:35 -07:00
committed by Facebook Github Bot
parent 40eba60cf5
commit 91230ae177
36 changed files with 863 additions and 606 deletions

View File

@@ -9,19 +9,23 @@
#include "YGInterop.h"
static YGInteropLoggerFunc gManagedFunc;
static YGInteropLogger gManagedLogger;
static int unmanagedLogger(YGLogLevel level, const char *format, va_list args) {
static int unmanagedLogger(const YGConfigRef config,
const YGNodeRef node,
YGLogLevel level,
const char *format,
va_list args) {
int result = 0;
if (gManagedFunc) {
char buffer[256];
result = vsnprintf(buffer, sizeof(buffer), format, args);
(*gManagedFunc)(level, buffer);
if (gManagedLogger) {
char message[8192];
result = vsnprintf(message, sizeof(message), format, args);
(*gManagedLogger)(config, node, level, message);
}
return result;
}
void YGInteropSetLogger(YGInteropLoggerFunc managedFunc) {
gManagedFunc = managedFunc;
YGSetLogger(&unmanagedLogger);
void YGInteropSetLogger(YGInteropLogger managedLogger) {
gManagedLogger = managedLogger;
YGSetLogger(YGConfigGetDefault(), &unmanagedLogger);
}

View File

@@ -13,8 +13,13 @@
YG_EXTERN_C_BEGIN
typedef void (*YGInteropLoggerFunc)(YGLogLevel level, const char *message);
typedef int (*YGInteropLogger)(const void *unmanagedConfigPtr,
const void *unmanagedNodePtr,
YGLogLevel level,
const char *message);
WIN_EXPORT void YGInteropSetLogger(YGInteropLoggerFunc managedFunc);
WIN_EXPORT YGConfigRef YGConfigGetDefault();
WIN_EXPORT void YGInteropSetLogger(YGInteropLogger managedLogger);
YG_EXTERN_C_END