Skip to content

Commit a810e68

Browse files
mhorowitzfacebook-github-bot
authored andcommitted
move nativeLoggingHook into AndroidJSCFactory
Reviewed By: fromcelticpark Differential Revision: D7803905 fbshipit-source-id: 797f5250a4a129a8dff3fb447c01837d68bea452
1 parent a363a7b commit a810e68

File tree

3 files changed

+23
-36
lines changed

3 files changed

+23
-36
lines changed

ReactAndroid/src/main/jni/react/jni/AndroidJSCFactory.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,29 @@ JSValueRef nativePerformanceNow(
7474
return Value::makeNumber(ctx, (nano / (double)NANOSECONDS_IN_MILLISECOND));
7575
}
7676

77+
JSValueRef nativeLoggingHook(
78+
JSContextRef ctx,
79+
JSObjectRef function,
80+
JSObjectRef thisObject,
81+
size_t argumentCount,
82+
const JSValueRef arguments[],
83+
JSValueRef* exception) {
84+
android_LogPriority logLevel = ANDROID_LOG_DEBUG;
85+
if (argumentCount > 1) {
86+
int level = (int)Value(ctx, arguments[1]).asNumber();
87+
// The lowest log level we get from JS is 0. We shift and cap it to be
88+
// in the range the Android logging method expects.
89+
logLevel = std::min(
90+
static_cast<android_LogPriority>(level + ANDROID_LOG_DEBUG),
91+
ANDROID_LOG_FATAL);
92+
}
93+
if (argumentCount > 0) {
94+
String message = Value(ctx, arguments[0]).toString();
95+
reactAndroidLoggingHook(message.str(), logLevel);
96+
}
97+
return Value::makeUndefined(ctx);
98+
}
99+
77100
}
78101

79102
namespace detail {

ReactAndroid/src/main/jni/react/jni/JSLogging.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,10 @@
33
#include "JSLogging.h"
44

55
#include <fb/log.h>
6-
#include <algorithm>
7-
8-
#include <jschelpers/Value.h>
96

107
namespace facebook {
118
namespace react {
129

13-
JSValueRef nativeLoggingHook(
14-
JSContextRef ctx,
15-
JSObjectRef function,
16-
JSObjectRef thisObject,
17-
size_t argumentCount,
18-
const JSValueRef arguments[],
19-
JSValueRef* exception) {
20-
android_LogPriority logLevel = ANDROID_LOG_DEBUG;
21-
if (argumentCount > 1) {
22-
int level = (int)Value(ctx, arguments[1]).asNumber();
23-
// The lowest log level we get from JS is 0. We shift and cap it to be
24-
// in the range the Android logging method expects.
25-
logLevel = std::min(
26-
static_cast<android_LogPriority>(level + ANDROID_LOG_DEBUG),
27-
ANDROID_LOG_FATAL);
28-
}
29-
if (argumentCount > 0) {
30-
String message = Value(ctx, arguments[0]).toString();
31-
reactAndroidLoggingHook(message.str(), logLevel);
32-
}
33-
return Value::makeUndefined(ctx);
34-
}
35-
3610
void reactAndroidLoggingHook(
3711
const std::string& message,
3812
android_LogPriority logLevel) {

ReactAndroid/src/main/jni/react/jni/JSLogging.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,9 @@
55
#include <android/log.h>
66
#include <string>
77

8-
#include <JavaScriptCore/JSContextRef.h>
9-
108
namespace facebook {
119
namespace react {
1210

13-
JSValueRef nativeLoggingHook(
14-
JSContextRef ctx,
15-
JSObjectRef function,
16-
JSObjectRef thisObject,
17-
size_t argumentCount,
18-
const JSValueRef arguments[],
19-
JSValueRef* exception);
20-
2111
void reactAndroidLoggingHook(
2212
const std::string& message,
2313
android_LogPriority logLevel);

0 commit comments

Comments
 (0)