Skip to content

Commit

Permalink
C++ style enums 5/N: LogLevel (#39447)
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/yoga#1387

Pull Request resolved: #39447

This converts usages of YGLogLevel to LogLevel

Reviewed By: rozele

Differential Revision: D49270695

fbshipit-source-id: 2ba5b4f2b0af93fef89dbbb2ce54c2f486670aac
  • Loading branch information
NickGerleman authored and pull[bot] committed Dec 13, 2023
1 parent 2c33e60 commit 9bf6c35
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/react-native/ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ void YGNodePrint(const YGNodeConstRef nodeRef, const YGPrintOptions options) {
const auto node = resolveRef(nodeRef);
std::string str;
yoga::nodeToString(str, node, options, 0);
yoga::log(node, YGLogLevelDebug, str.c_str());
yoga::log(node, LogLevel::Debug, str.c_str());
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2526,14 +2526,14 @@ bool calculateLayoutInternal(
if (gPrintChanges && gPrintSkips) {
yoga::log(
node,
YGLogLevelVerbose,
LogLevel::Verbose,
"%s%d.{[skipped] ",
spacerWithLength(depth),
depth);
node->print();
yoga::log(
node,
YGLogLevelVerbose,
LogLevel::Verbose,
"wm: %s, hm: %s, aw: %f ah: %f => d: (%f, %f) %s\n",
measureModeName(widthMeasureMode, performLayout),
measureModeName(heightMeasureMode, performLayout),
Expand All @@ -2547,15 +2547,15 @@ bool calculateLayoutInternal(
if (gPrintChanges) {
yoga::log(
node,
YGLogLevelVerbose,
LogLevel::Verbose,
"%s%d.{%s",
spacerWithLength(depth),
depth,
needToVisitNode ? "*" : "");
node->print();
yoga::log(
node,
YGLogLevelVerbose,
LogLevel::Verbose,
"wm: %s, hm: %s, aw: %f ah: %f %s\n",
measureModeName(widthMeasureMode, performLayout),
measureModeName(heightMeasureMode, performLayout),
Expand All @@ -2582,15 +2582,15 @@ bool calculateLayoutInternal(
if (gPrintChanges) {
yoga::log(
node,
YGLogLevelVerbose,
LogLevel::Verbose,
"%s%d.}%s",
spacerWithLength(depth),
depth,
needToVisitNode ? "*" : "");
node->print();
yoga::log(
node,
YGLogLevelVerbose,
LogLevel::Verbose,
"wm: %s, hm: %s, d: (%f, %f) %s\n",
measureModeName(widthMeasureMode, performLayout),
measureModeName(heightMeasureMode, performLayout),
Expand All @@ -2609,7 +2609,7 @@ bool calculateLayoutInternal(
if (layout->nextCachedMeasurementsIndex ==
LayoutResults::MaxCachedMeasurements) {
if (gPrintChanges) {
yoga::log(node, YGLogLevelVerbose, "Out of cache entries!\n");
yoga::log(node, LogLevel::Verbose, "Out of cache entries!\n");
}
layout->nextCachedMeasurementsIndex = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native/ReactCommon/yoga/yoga/config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ void Config::setLogger(YGLogger logger) {

void Config::log(
const yoga::Node* node,
YGLogLevel logLevel,
LogLevel logLevel,
const char* format,
va_list args) const {
logger_(this, node, logLevel, format, args);
logger_(this, node, unscopedEnum(logLevel), format, args);
}

void Config::setCloneNodeCallback(YGCloneNodeFunc cloneNode) {
Expand Down
3 changes: 2 additions & 1 deletion packages/react-native/ReactCommon/yoga/yoga/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <yoga/Yoga.h>
#include <yoga/enums/Errata.h>
#include <yoga/enums/ExperimentalFeature.h>
#include <yoga/enums/LogLevel.h>

// Tag struct used to form the opaque YGConfigRef for the public C API
struct YGConfig {};
Expand Down Expand Up @@ -67,7 +68,7 @@ class YG_EXPORT Config : public ::YGConfig {
void setLogger(YGLogger logger);
void log(
const yoga::Node* node,
YGLogLevel logLevel,
LogLevel logLevel,
const char* format,
va_list args) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace facebook::yoga {

void assertFatal(const bool condition, const char* message) {
if (!condition) {
yoga::log(YGLogLevelFatal, "%s\n", message);
yoga::log(LogLevel::Fatal, "%s\n", message);
fatalWithMessage(message);
}
}
Expand All @@ -32,7 +32,7 @@ void assertFatalWithNode(
const bool condition,
const char* message) {
if (!condition) {
yoga::log(node, YGLogLevelFatal, "%s\n", message);
yoga::log(node, LogLevel::Fatal, "%s\n", message);
fatalWithMessage(message);
}
}
Expand All @@ -42,7 +42,7 @@ void assertFatalWithConfig(
const bool condition,
const char* message) {
if (!condition) {
yoga::log(config, YGLogLevelFatal, "%s\n", message);
yoga::log(config, LogLevel::Fatal, "%s\n", message);
fatalWithMessage(message);
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/react-native/ReactCommon/yoga/yoga/debug/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ namespace {
void vlog(
const yoga::Config* config,
const yoga::Node* node,
YGLogLevel level,
LogLevel level,
const char* format,
va_list args) {
if (config == nullptr) {
getDefaultLogger()(nullptr, node, level, format, args);
getDefaultLogger()(nullptr, node, unscopedEnum(level), format, args);
} else {
config->log(node, level, format, args);
}
}
} // namespace

void log(YGLogLevel level, const char* format, ...) noexcept {
void log(LogLevel level, const char* format, ...) noexcept {
va_list args;
va_start(args, format);
vlog(nullptr, nullptr, level, format, args);
Expand All @@ -38,7 +38,7 @@ void log(YGLogLevel level, const char* format, ...) noexcept {

void log(
const yoga::Node* node,
YGLogLevel level,
LogLevel level,
const char* format,
...) noexcept {
va_list args;
Expand All @@ -50,7 +50,7 @@ void log(

void log(
const yoga::Config* config,
YGLogLevel level,
LogLevel level,
const char* format,
...) noexcept {
va_list args;
Expand Down
8 changes: 4 additions & 4 deletions packages/react-native/ReactCommon/yoga/yoga/debug/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@

#include <yoga/Yoga.h>

#include <yoga/YGEnums.h>
#include <yoga/config/Config.h>
#include <yoga/enums/LogLevel.h>
#include <yoga/node/Node.h>

namespace facebook::yoga {

void log(YGLogLevel level, const char* format, ...) noexcept;
void log(LogLevel level, const char* format, ...) noexcept;

void log(
const yoga::Node* node,
YGLogLevel level,
LogLevel level,
const char* message,
...) noexcept;

void log(
const yoga::Config* config,
YGLogLevel level,
LogLevel level,
const char* format,
...) noexcept;

Expand Down

0 comments on commit 9bf6c35

Please sign in to comment.