Permalink
Browse files

Made logging logic dynamic to log string length

Reviewed By: emilsjolander

Differential Revision: D6784491

fbshipit-source-id: 26e4520a84be355ff992b808297ce7a95b3d09e3
  • Loading branch information...
priteshrnandgaonkar authored and facebook-github-bot committed Jan 23, 2018
1 parent 6fa039d commit be8e7c6e65724d4915862098238506172dbe9657
@@ -158,8 +158,9 @@ static int YGJNILogFunc(const YGConfigRef config,
YGLogLevel level,
const char *format,
va_list args) {
char buffer[256];
int result = vsnprintf(buffer, sizeof(buffer), format, args);
int result = vsnprintf(NULL, 0, format, args);
std::vector<char> buffer(1 + result);
vsnprintf(buffer.data(), buffer.size(), format, args);
static auto logFunc =
findClassStatic("com/facebook/yoga/YogaLogger")
@@ -170,10 +171,12 @@ static int YGJNILogFunc(const YGConfigRef config,
if (auto obj = YGNodeJobject(node)->lockLocal()) {
auto jlogger = reinterpret_cast<global_ref<jobject> *>(YGConfigGetContext(config));
logFunc(jlogger->get(),
obj,
logLevelFromInt(JYogaLogLevel::javaClassStatic(), static_cast<jint>(level)),
Environment::current()->NewStringUTF(buffer));
logFunc(
jlogger->get(),
obj,
logLevelFromInt(
JYogaLogLevel::javaClassStatic(), static_cast<jint>(level)),
Environment::current()->NewStringUTF(buffer.data()));
}
return result;
@@ -29,15 +29,15 @@ static bool areFourValuesEqual(const std::array<YGValue, YGEdgeCount>& four) {
}
static void appendFormatedString(string* str, const char* fmt, ...) {
char buffer[1024];
va_list args;
va_start(args, fmt);
va_list argsCopy;
va_copy(argsCopy, args);
std::vector<char> buf(1 + vsnprintf(NULL, 0, fmt, args));
va_end(args);
vsnprintf(buffer, 1024, fmt, argsCopy);
vsnprintf(buf.data(), buf.size(), fmt, argsCopy);
va_end(argsCopy);
string result = string(buffer);
string result = string(buf.begin(), buf.end() - 1);
str->append(result);
}

0 comments on commit be8e7c6

Please sign in to comment.