Skip to content

Commit 3f1412a

Browse files
javachefacebook-github-bot
authored andcommitted
Remove unnecessary interpolation for logcat logging (#48567)
Summary: We don't need the `FBLOG_PRI` macro which does unnecessary additional interpolation, and can instead directly call `__android_log_write` Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D67461225
1 parent 1051bd8 commit 3f1412a

File tree

4 files changed

+8
-24
lines changed

4 files changed

+8
-24
lines changed

packages/react-native/ReactAndroid/src/main/jni/react/hermes/reactexecutor/OnLoad.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ static ::hermes::vm::RuntimeConfig makeRuntimeConfig(jlong heapSizeMB) {
4141
}
4242

4343
static void installBindings(jsi::Runtime& runtime) {
44-
react::Logger androidLogger =
45-
static_cast<void (*)(const std::string&, unsigned int)>(
46-
&reactAndroidLoggingHook);
47-
react::bindNativeLogger(runtime, androidLogger);
44+
react::bindNativeLogger(runtime, &reactAndroidLoggingHook);
4845
}
4946

5047
class HermesExecutorHolder

packages/react-native/ReactAndroid/src/main/jni/react/jni/JSLogging.cpp

+4-9
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,16 @@
77

88
#include "JSLogging.h"
99

10-
#include <fb/log.h>
10+
#include <android/log.h>
1111

1212
namespace facebook::react {
1313

14-
void reactAndroidLoggingHook(
15-
const std::string& message,
16-
android_LogPriority logLevel) {
17-
FBLOG_PRI(logLevel, "ReactNativeJS", "%s", message.c_str());
18-
}
19-
2014
void reactAndroidLoggingHook(
2115
const std::string& message,
2216
unsigned int logLevel) {
23-
reactAndroidLoggingHook(
24-
message, static_cast<android_LogPriority>(logLevel + ANDROID_LOG_DEBUG));
17+
auto logPriority =
18+
static_cast<android_LogPriority>(logLevel + ANDROID_LOG_DEBUG);
19+
__android_log_write(logPriority, "ReactNativeJS", message.c_str());
2520
}
2621

2722
} // namespace facebook::react

packages/react-native/ReactAndroid/src/main/jni/react/jni/JSLogging.h

-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@
77

88
#pragma once
99

10-
#include <android/log.h>
1110
#include <string>
1211

1312
namespace facebook::react {
1413

15-
void reactAndroidLoggingHook(
16-
const std::string& message,
17-
android_LogPriority logLevel);
1814
void reactAndroidLoggingHook(const std::string& message, unsigned int logLevel);
1915

2016
} // namespace facebook::react

packages/react-native/ReactAndroid/src/main/jni/react/jscexecutor/OnLoad.cpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,13 @@ class JSCExecutorFactory : public JSExecutorFactory {
2424
std::unique_ptr<JSExecutor> createJSExecutor(
2525
std::shared_ptr<ExecutorDelegate> delegate,
2626
std::shared_ptr<MessageQueueThread> jsQueue) override {
27-
auto installBindings = [](jsi::Runtime& runtime) {
28-
react::Logger androidLogger =
29-
static_cast<void (*)(const std::string&, unsigned int)>(
30-
&reactAndroidLoggingHook);
31-
react::bindNativeLogger(runtime, androidLogger);
32-
};
3327
return std::make_unique<JSIExecutor>(
3428
jsc::makeJSCRuntime(),
3529
delegate,
3630
JSIExecutor::defaultTimeoutInvoker,
37-
installBindings);
31+
[](jsi::Runtime& runtime) {
32+
react::bindNativeLogger(runtime, &reactAndroidLoggingHook);
33+
});
3834
}
3935
};
4036

0 commit comments

Comments
 (0)