Emit soft error for warning

Summary:
This diff adds a default behavior for the unified logger on Android.

Added the call site in the CXXNativeModule.

Changelog: [internal]

Reviewed By: JoshuaGross

Differential Revision: D30377767

fbshipit-source-id: 000014828f2f245dc9492e3617218895d9a33536
This commit is contained in:
Sota Ogo
2021-08-18 23:38:01 -07:00
committed by Facebook GitHub Bot
parent 10cd2730af
commit b29a78732d
9 changed files with 61 additions and 29 deletions
+22 -18
View File
@@ -16,6 +16,8 @@
#include "MessageQueueThread.h"
#include "SystraceSection.h"
#include <logger/react_native_log.h>
using facebook::xplat::module::CxxModule;
namespace facebook {
namespace react {
@@ -54,10 +56,24 @@ CxxModule::Callback convertCallback(
} // namespace
WarnOnUsageLogger CxxNativeModule::warnOnUsageLogger_ = nullptr;
bool CxxNativeModule::shouldWarnOnUse_ = false;
void CxxNativeModule::setWarnOnUsageLogger(WarnOnUsageLogger logger) {
warnOnUsageLogger_ = logger;
void CxxNativeModule::setShouldWarnOnUse(bool value) {
shouldWarnOnUse_ = value;
}
void CxxNativeModule::emitWarnIfWarnOnUsage(
const std::string &method_name,
const std::string &module_name) {
if (shouldWarnOnUse_) {
std::string message = folly::to<std::string>(
"Calling ",
method_name,
" on Cxx NativeModule (name = \"",
module_name,
"\").");
react_native_log_warn(message.c_str());
}
}
std::string CxxNativeModule::getName() {
@@ -93,11 +109,7 @@ folly::dynamic CxxNativeModule::getConstants() {
return nullptr;
}
if (warnOnUsageLogger_) {
warnOnUsageLogger_(
"Calling getConstants() on Cxx NativeModule (name = \"" + getName() +
"\").");
}
emitWarnIfWarnOnUsage("getConstants()", getName());
folly::dynamic constants = folly::dynamic::object();
for (auto &pair : module_->getConstants()) {
@@ -133,11 +145,7 @@ void CxxNativeModule::invoke(
"Method ", method.name, " is synchronous but invoked asynchronously"));
}
if (warnOnUsageLogger_) {
warnOnUsageLogger_(
"Calling " + method.name + "() on Cxx NativeModule (name = \"" +
getName() + "\").");
}
emitWarnIfWarnOnUsage(method.name, getName());
if (params.size() < method.callbacks) {
throw std::invalid_argument(folly::to<std::string>(
@@ -222,11 +230,7 @@ MethodCallResult CxxNativeModule::callSerializableNativeHook(
"Method ", method.name, " is asynchronous but invoked synchronously"));
}
if (warnOnUsageLogger_) {
warnOnUsageLogger_(
"Calling " + method.name + "() on Cxx NativeModule (name = \"" +
getName() + "\").");
}
emitWarnIfWarnOnUsage(method.name, getName());
return method.syncFunc(std::move(args));
}