mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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:
committed by
Facebook GitHub Bot
parent
10cd2730af
commit
b29a78732d
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user