Skip to content

Commit

Permalink
Remove unnecessary interpolation for logcat logging (#48567)
Browse files Browse the repository at this point in the history
Summary:

We don't need the `FBLOG_PRI` macro which does unnecessary additional interpolation, and can instead directly call `__android_log_write`

Changelog: [Internal]

Differential Revision: D67461225
  • Loading branch information
javache authored and facebook-github-bot committed Jan 9, 2025
1 parent b5155fb commit d3582c4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ static ::hermes::vm::RuntimeConfig makeRuntimeConfig(jlong heapSizeMB) {
}

static void installBindings(jsi::Runtime& runtime) {
react::Logger androidLogger =
static_cast<void (*)(const std::string&, unsigned int)>(
&reactAndroidLoggingHook);
react::bindNativeLogger(runtime, androidLogger);
react::bindNativeLogger(runtime, &reactAndroidLoggingHook);
}

class HermesExecutorHolder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,16 @@

#include "JSLogging.h"

#include <fb/log.h>
#include <android/log.h>

namespace facebook::react {

void reactAndroidLoggingHook(
const std::string& message,
android_LogPriority logLevel) {
FBLOG_PRI(logLevel, "ReactNativeJS", "%s", message.c_str());
}

void reactAndroidLoggingHook(
const std::string& message,
unsigned int logLevel) {
reactAndroidLoggingHook(
message, static_cast<android_LogPriority>(logLevel + ANDROID_LOG_DEBUG));
auto logPriority =
static_cast<android_LogPriority>(logLevel + ANDROID_LOG_DEBUG);
__android_log_write(logPriority, "ReactNativeJS", message.c_str());
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@

#pragma once

#include <android/log.h>
#include <string>

namespace facebook::react {

void reactAndroidLoggingHook(
const std::string& message,
android_LogPriority logLevel);
void reactAndroidLoggingHook(const std::string& message, unsigned int logLevel);

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ class JSCExecutorFactory : public JSExecutorFactory {
std::unique_ptr<JSExecutor> createJSExecutor(
std::shared_ptr<ExecutorDelegate> delegate,
std::shared_ptr<MessageQueueThread> jsQueue) override {
auto installBindings = [](jsi::Runtime& runtime) {
react::Logger androidLogger =
static_cast<void (*)(const std::string&, unsigned int)>(
&reactAndroidLoggingHook);
react::bindNativeLogger(runtime, androidLogger);
};
return std::make_unique<JSIExecutor>(
jsc::makeJSCRuntime(),
delegate,
JSIExecutor::defaultTimeoutInvoker,
installBindings);
[](jsi::Runtime& runtime) {
react::bindNativeLogger(runtime, &reactAndroidLoggingHook);
});
}
};

Expand Down

0 comments on commit d3582c4

Please sign in to comment.