Cleanup Android logger code (#1367)
Summary: X-link: https://github.com/facebook/react-native/pull/39373 Pull Request resolved: https://github.com/facebook/yoga/pull/1367 Moves some messiness around conditionally using Android's logger to `Log.cpp`, isolated to within a single function. Reviewed By: rshest Differential Revision: D49131964 fbshipit-source-id: cdff8af1d4df6ae28f00eecfed1920c71eec24d0
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c35f8819ae
commit
a003c09a4c
@@ -20,75 +20,6 @@
|
|||||||
using namespace facebook;
|
using namespace facebook;
|
||||||
using namespace facebook::yoga;
|
using namespace facebook::yoga;
|
||||||
|
|
||||||
#ifdef ANDROID
|
|
||||||
static int YGAndroidLog(
|
|
||||||
const YGConfigConstRef config,
|
|
||||||
const YGNodeConstRef node,
|
|
||||||
YGLogLevel level,
|
|
||||||
const char* format,
|
|
||||||
va_list args);
|
|
||||||
#else
|
|
||||||
static int YGDefaultLog(
|
|
||||||
const YGConfigConstRef config,
|
|
||||||
const YGNodeConstRef node,
|
|
||||||
YGLogLevel level,
|
|
||||||
const char* format,
|
|
||||||
va_list args);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ANDROID
|
|
||||||
#include <android/log.h>
|
|
||||||
static int YGAndroidLog(
|
|
||||||
const YGConfigConstRef /*config*/,
|
|
||||||
const YGNodeConstRef /*node*/,
|
|
||||||
YGLogLevel level,
|
|
||||||
const char* format,
|
|
||||||
va_list args) {
|
|
||||||
int androidLevel = YGLogLevelDebug;
|
|
||||||
switch (level) {
|
|
||||||
case YGLogLevelFatal:
|
|
||||||
androidLevel = ANDROID_LOG_FATAL;
|
|
||||||
break;
|
|
||||||
case YGLogLevelError:
|
|
||||||
androidLevel = ANDROID_LOG_ERROR;
|
|
||||||
break;
|
|
||||||
case YGLogLevelWarn:
|
|
||||||
androidLevel = ANDROID_LOG_WARN;
|
|
||||||
break;
|
|
||||||
case YGLogLevelInfo:
|
|
||||||
androidLevel = ANDROID_LOG_INFO;
|
|
||||||
break;
|
|
||||||
case YGLogLevelDebug:
|
|
||||||
androidLevel = ANDROID_LOG_DEBUG;
|
|
||||||
break;
|
|
||||||
case YGLogLevelVerbose:
|
|
||||||
androidLevel = ANDROID_LOG_VERBOSE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
const int result = __android_log_vprint(androidLevel, "yoga", format, args);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
static int YGDefaultLog(
|
|
||||||
const YGConfigConstRef /*config*/,
|
|
||||||
const YGNodeConstRef /*node*/,
|
|
||||||
YGLogLevel level,
|
|
||||||
const char* format,
|
|
||||||
va_list args) {
|
|
||||||
switch (level) {
|
|
||||||
case YGLogLevelError:
|
|
||||||
case YGLogLevelFatal:
|
|
||||||
return vfprintf(stderr, format, args);
|
|
||||||
case YGLogLevelWarn:
|
|
||||||
case YGLogLevelInfo:
|
|
||||||
case YGLogLevelDebug:
|
|
||||||
case YGLogLevelVerbose:
|
|
||||||
default:
|
|
||||||
return vprintf(format, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
YOGA_EXPORT bool YGFloatIsUndefined(const float value) {
|
YOGA_EXPORT bool YGFloatIsUndefined(const float value) {
|
||||||
return yoga::isUndefined(value);
|
return yoga::isUndefined(value);
|
||||||
}
|
}
|
||||||
@@ -260,12 +191,7 @@ YOGA_EXPORT void YGNodeReset(YGNodeRef node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGConfigRef YGConfigNew(void) {
|
YOGA_EXPORT YGConfigRef YGConfigNew(void) {
|
||||||
#ifdef ANDROID
|
return new yoga::Config(getDefaultLogger());
|
||||||
const YGConfigRef config = new yoga::Config(YGAndroidLog);
|
|
||||||
#else
|
|
||||||
const YGConfigRef config = new yoga::Config(YGDefaultLog);
|
|
||||||
#endif
|
|
||||||
return config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGConfigFree(const YGConfigRef config) {
|
YOGA_EXPORT void YGConfigFree(const YGConfigRef config) {
|
||||||
@@ -960,11 +886,7 @@ YOGA_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) {
|
|||||||
if (logger != nullptr) {
|
if (logger != nullptr) {
|
||||||
resolveRef(config)->setLogger(logger);
|
resolveRef(config)->setLogger(logger);
|
||||||
} else {
|
} else {
|
||||||
#ifdef ANDROID
|
resolveRef(config)->setLogger(getDefaultLogger());
|
||||||
resolveRef(config)->setLogger(&YGAndroidLog);
|
|
||||||
#else
|
|
||||||
resolveRef(config)->setLogger(&YGDefaultLog);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,6 +7,10 @@
|
|||||||
|
|
||||||
#include <yoga/debug/Log.h>
|
#include <yoga/debug/Log.h>
|
||||||
|
|
||||||
|
#ifdef ANDROID
|
||||||
|
#include <android/log.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -62,4 +66,49 @@ void log(
|
|||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
YGLogger getDefaultLogger() {
|
||||||
|
return [](const YGConfigConstRef /*config*/,
|
||||||
|
const YGNodeConstRef /*node*/,
|
||||||
|
YGLogLevel level,
|
||||||
|
const char* format,
|
||||||
|
va_list args) -> int {
|
||||||
|
#ifdef ANDROID
|
||||||
|
int androidLevel = YGLogLevelDebug;
|
||||||
|
switch (level) {
|
||||||
|
case YGLogLevelFatal:
|
||||||
|
androidLevel = ANDROID_LOG_FATAL;
|
||||||
|
break;
|
||||||
|
case YGLogLevelError:
|
||||||
|
androidLevel = ANDROID_LOG_ERROR;
|
||||||
|
break;
|
||||||
|
case YGLogLevelWarn:
|
||||||
|
androidLevel = ANDROID_LOG_WARN;
|
||||||
|
break;
|
||||||
|
case YGLogLevelInfo:
|
||||||
|
androidLevel = ANDROID_LOG_INFO;
|
||||||
|
break;
|
||||||
|
case YGLogLevelDebug:
|
||||||
|
androidLevel = ANDROID_LOG_DEBUG;
|
||||||
|
break;
|
||||||
|
case YGLogLevelVerbose:
|
||||||
|
androidLevel = ANDROID_LOG_VERBOSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return __android_log_vprint(androidLevel, "yoga", format, args);
|
||||||
|
#else
|
||||||
|
switch (level) {
|
||||||
|
case YGLogLevelError:
|
||||||
|
case YGLogLevelFatal:
|
||||||
|
return vfprintf(stderr, format, args);
|
||||||
|
case YGLogLevelWarn:
|
||||||
|
case YGLogLevelInfo:
|
||||||
|
case YGLogLevelDebug:
|
||||||
|
case YGLogLevelVerbose:
|
||||||
|
default:
|
||||||
|
return vprintf(format, args);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace facebook::yoga
|
} // namespace facebook::yoga
|
||||||
|
@@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
#include <yoga/YGEnums.h>
|
#include <yoga/YGEnums.h>
|
||||||
#include <yoga/node/Node.h>
|
#include <yoga/node/Node.h>
|
||||||
#include <yoga/config/Config.h>
|
#include <yoga/config/Config.h>
|
||||||
@@ -29,4 +31,6 @@ void log(
|
|||||||
const char* format,
|
const char* format,
|
||||||
...) noexcept;
|
...) noexcept;
|
||||||
|
|
||||||
|
YGLogger getDefaultLogger();
|
||||||
|
|
||||||
} // namespace facebook::yoga
|
} // namespace facebook::yoga
|
||||||
|
Reference in New Issue
Block a user