Skip to content

Adding logging support on droid and logging failure message #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
#include <react/jni/JSLogging.h>
#include <react/jni/ReadableNativeMap.h>

namespace facebook {
namespace v8runtime {
std::unique_ptr<jsi::Runtime> makeV8Runtime();
} // namespace v8runtime
} // namespace facebook

namespace facebook {
namespace react {

Expand All @@ -31,13 +25,16 @@ class V8ExecutorFactory : public JSExecutorFactory {

std::unique_ptr<JSExecutor> createJSExecutor(
std::shared_ptr<ExecutorDelegate> delegate,
std::shared_ptr<MessageQueueThread> jsQueue) override {
std::shared_ptr<MessageQueueThread> jsQueue) override {

auto logger = std::make_shared<JSIExecutor::Logger>([](const std::string& message, unsigned int logLevel) {
reactAndroidLoggingHook(message, logLevel);
});

return folly::make_unique<JSIExecutor>(
facebook::v8runtime::makeV8Runtime(m_v8Config),
facebook::v8runtime::makeV8Runtime(m_v8Config, logger),
delegate,
[](const std::string& message, unsigned int logLevel) {
reactAndroidLoggingHook(message, logLevel);
},
*logger,
JSIExecutor::defaultTimeoutInvoker,
nullptr);
}
Expand Down
2 changes: 1 addition & 1 deletion ReactCommon/jsi/V8Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace v8runtime {
std::unique_ptr<const jsi::Buffer> custom_snapshot = nullptr); /*Optional*/

std::unique_ptr<jsi::Runtime> makeV8Runtime();
std::unique_ptr<jsi::Runtime> makeV8Runtime(const folly::dynamic& v8Config);
std::unique_ptr<jsi::Runtime> makeV8Runtime(const folly::dynamic& v8Config, const std::shared_ptr<Logger>& logger);

} // namespace v8runtime
} // namespace facebook
3 changes: 2 additions & 1 deletion ReactCommon/jsi/V8Runtime_droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ namespace facebook { namespace v8runtime {
}
}

V8Runtime::V8Runtime(const folly::dynamic& v8Config) : V8Runtime() {
V8Runtime::V8Runtime(const folly::dynamic& v8Config, const std::shared_ptr<Logger>& logger) : V8Runtime() {
logger_ = logger;
isCacheEnabled_ = IsCacheEnabled(v8Config);
shouldProduceFullCache_ = ShouldProduceFullCache(v8Config);
shouldSetNoLazyFlag_ = ShouldSetNoLazyFlag(v8Config);
Expand Down
8 changes: 7 additions & 1 deletion ReactCommon/jsi/V8Runtime_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace facebook { namespace v8runtime {
class V8Runtime : public jsi::Runtime {
public:
V8Runtime();
V8Runtime(const folly::dynamic& v8Config);
V8Runtime(const folly::dynamic& v8Config, const std::shared_ptr<Logger>& logger);

V8Runtime(const v8::Platform* platform, std::shared_ptr<Logger>&& logger,
std::shared_ptr<facebook::react::MessageQueueThread>&& jsQueue, std::shared_ptr<CacheProvider>&& cacheProvider,
Expand Down Expand Up @@ -374,6 +374,12 @@ namespace facebook { namespace v8runtime {
bool ExecuteString(v8::Local<v8::String> source, const jsi::Buffer* cache, v8::Local<v8::Value> name, bool report_exceptions);
bool ExecuteString(const v8::Local<v8::String>& source, const std::string& sourceURL);

void Log(const std::string& message, const unsigned int logLevel) {
if (logger_) {
(*logger_)("V8Runtime:: " + message, logLevel);
}
}

void ReportException(v8::TryCatch* try_catch);

v8::Isolate* GetIsolate() const { return isolate_; }
Expand Down
14 changes: 9 additions & 5 deletions ReactCommon/jsi/V8Runtime_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ namespace facebook { namespace v8runtime {
if (message.IsEmpty()) {
// V8 didn't provide any extra information about this error; just
// throw the exception.
throw jsi::JSError(*this, "<Unknown exception>");
std::string errorMessage{ "<Unknown exception>" };
Log(errorMessage, 3 /*LogLevel error*/);
throw jsi::JSError(*this, errorMessage);
}
else {
// Print (filename):(line number): (message).
Expand Down Expand Up @@ -283,7 +285,9 @@ namespace facebook { namespace v8runtime {
sstr << stack_trace_string2 << std::endl;
}

throw jsi::JSError(*this, sstr.str());
std::string errorMessage{ sstr.str() };
Log(errorMessage, 3 /*LogLevel error*/);
throw jsi::JSError(*this, errorMessage);
}
}

Expand Down Expand Up @@ -740,7 +744,7 @@ namespace facebook { namespace v8runtime {
return std::make_unique<V8Runtime>();
}

std::unique_ptr<jsi::Runtime> makeV8Runtime(const folly::dynamic& v8Config) {
return std::make_unique<V8Runtime>(v8Config);
std::unique_ptr<jsi::Runtime> makeV8Runtime(const folly::dynamic& v8Config, const std::shared_ptr<Logger>& logger) {
return std::make_unique<V8Runtime>(v8Config, logger);
}
}} // namespace facebook::v8runtime
}} // namespace facebook::v8runtime