Add nativeLoggingHook to JSIExecutor

Reviewed By: danzimm

Differential Revision: D7203114

fbshipit-source-id: 2f4640d19267dc4d75f6d6c8a7876c92abc22276
This commit is contained in:
Riley Dulin 2018-03-27 10:43:27 -07:00 committed by Facebook Github Bot
parent f5207ba9c7
commit 0150a0c85b
3 changed files with 34 additions and 7 deletions

View File

@ -8,6 +8,7 @@ EXPORTED_HEADERS = [
"JavaModuleWrapper.h",
"JavaScriptExecutorHolder.h",
"JSLoader.h",
"JSLogging.h",
"MethodInvoker.h",
"ModuleRegistryBuilder.h",
"NativeArray.h",

View File

@ -2,9 +2,8 @@
#include "JSLogging.h"
#include <android/log.h>
#include <algorithm>
#include <fb/log.h>
#include <algorithm>
#include <jschelpers/Value.h>
@ -16,7 +15,8 @@ JSValueRef nativeLoggingHook(
JSObjectRef function,
JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception) {
const JSValueRef arguments[],
JSValueRef* exception) {
android_LogPriority logLevel = ANDROID_LOG_DEBUG;
if (argumentCount > 1) {
int level = (int)Value(ctx, arguments[1]).asNumber();
@ -28,9 +28,23 @@ JSValueRef nativeLoggingHook(
}
if (argumentCount > 0) {
String message = Value(ctx, arguments[0]).toString();
FBLOG_PRI(logLevel, "ReactNativeJS", "%s", message.str().c_str());
reactAndroidLoggingHook(message.str(), logLevel);
}
return Value::makeUndefined(ctx);
}
}};
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));
}
} // namespace react
} // namespace facebook

View File

@ -2,6 +2,9 @@
#pragma once
#include <android/log.h>
#include <string>
#include <JavaScriptCore/JSContextRef.h>
namespace facebook {
@ -12,6 +15,15 @@ JSValueRef nativeLoggingHook(
JSObjectRef function,
JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception);
const JSValueRef arguments[],
JSValueRef* exception);
}}
void reactAndroidLoggingHook(
const std::string& message,
android_LogPriority logLevel);
void reactAndroidLoggingHook(
const std::string& message,
unsigned int logLevel);
} // namespace react
} // namespace facebook