From a810e6875fc5b6d1e1545c34910a109450b5aacd Mon Sep 17 00:00:00 2001 From: Marc Horowitz Date: Wed, 9 May 2018 22:01:58 -0700 Subject: [PATCH] move nativeLoggingHook into AndroidJSCFactory Reviewed By: fromcelticpark Differential Revision: D7803905 fbshipit-source-id: 797f5250a4a129a8dff3fb447c01837d68bea452 --- .../main/jni/react/jni/AndroidJSCFactory.cpp | 23 ++++++++++++++++ .../src/main/jni/react/jni/JSLogging.cpp | 26 ------------------- .../src/main/jni/react/jni/JSLogging.h | 10 ------- 3 files changed, 23 insertions(+), 36 deletions(-) diff --git a/ReactAndroid/src/main/jni/react/jni/AndroidJSCFactory.cpp b/ReactAndroid/src/main/jni/react/jni/AndroidJSCFactory.cpp index 88b80bd47..5208152f5 100644 --- a/ReactAndroid/src/main/jni/react/jni/AndroidJSCFactory.cpp +++ b/ReactAndroid/src/main/jni/react/jni/AndroidJSCFactory.cpp @@ -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(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 { diff --git a/ReactAndroid/src/main/jni/react/jni/JSLogging.cpp b/ReactAndroid/src/main/jni/react/jni/JSLogging.cpp index e17854215..02cd21ddd 100644 --- a/ReactAndroid/src/main/jni/react/jni/JSLogging.cpp +++ b/ReactAndroid/src/main/jni/react/jni/JSLogging.cpp @@ -3,36 +3,10 @@ #include "JSLogging.h" #include -#include - -#include 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(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) { diff --git a/ReactAndroid/src/main/jni/react/jni/JSLogging.h b/ReactAndroid/src/main/jni/react/jni/JSLogging.h index 5e4e99143..aaf5718cc 100644 --- a/ReactAndroid/src/main/jni/react/jni/JSLogging.h +++ b/ReactAndroid/src/main/jni/react/jni/JSLogging.h @@ -5,19 +5,9 @@ #include #include -#include - 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);