move nativeLoggingHook into AndroidJSCFactory

Reviewed By: fromcelticpark

Differential Revision: D7803905

fbshipit-source-id: 797f5250a4a129a8dff3fb447c01837d68bea452
This commit is contained in:
Marc Horowitz 2018-05-09 22:01:58 -07:00 committed by Facebook Github Bot
parent a363a7b501
commit a810e6875f
3 changed files with 23 additions and 36 deletions

View File

@ -74,6 +74,29 @@ JSValueRef nativePerformanceNow(
return Value::makeNumber(ctx, (nano / (double)NANOSECONDS_IN_MILLISECOND));
}
JSValueRef nativeLoggingHook(
JSContextRef ctx,
JSObjectRef function,
JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef* exception) {
android_LogPriority logLevel = ANDROID_LOG_DEBUG;
if (argumentCount > 1) {
int level = (int)Value(ctx, arguments[1]).asNumber();
// The lowest log level we get from JS is 0. We shift and cap it to be
// in the range the Android logging method expects.
logLevel = std::min(
static_cast<android_LogPriority>(level + ANDROID_LOG_DEBUG),
ANDROID_LOG_FATAL);
}
if (argumentCount > 0) {
String message = Value(ctx, arguments[0]).toString();
reactAndroidLoggingHook(message.str(), logLevel);
}
return Value::makeUndefined(ctx);
}
}
namespace detail {

View File

@ -3,36 +3,10 @@
#include "JSLogging.h"
#include <fb/log.h>
#include <algorithm>
#include <jschelpers/Value.h>
namespace facebook {
namespace react {
JSValueRef nativeLoggingHook(
JSContextRef ctx,
JSObjectRef function,
JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef* exception) {
android_LogPriority logLevel = ANDROID_LOG_DEBUG;
if (argumentCount > 1) {
int level = (int)Value(ctx, arguments[1]).asNumber();
// The lowest log level we get from JS is 0. We shift and cap it to be
// in the range the Android logging method expects.
logLevel = std::min(
static_cast<android_LogPriority>(level + ANDROID_LOG_DEBUG),
ANDROID_LOG_FATAL);
}
if (argumentCount > 0) {
String message = Value(ctx, arguments[0]).toString();
reactAndroidLoggingHook(message.str(), logLevel);
}
return Value::makeUndefined(ctx);
}
void reactAndroidLoggingHook(
const std::string& message,
android_LogPriority logLevel) {

View File

@ -5,19 +5,9 @@
#include <android/log.h>
#include <string>
#include <JavaScriptCore/JSContextRef.h>
namespace facebook {
namespace react {
JSValueRef nativeLoggingHook(
JSContextRef ctx,
JSObjectRef function,
JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef* exception);
void reactAndroidLoggingHook(
const std::string& message,
android_LogPriority logLevel);