File tree Expand file tree Collapse file tree 3 files changed +23
-36
lines changed
ReactAndroid/src/main/jni/react/jni Expand file tree Collapse file tree 3 files changed +23
-36
lines changed Original file line number Diff line number Diff 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
79102namespace detail {
Original file line number Diff line number Diff line change 33#include " JSLogging.h"
44
55#include < fb/log.h>
6- #include < algorithm>
7-
8- #include < jschelpers/Value.h>
96
107namespace facebook {
118namespace 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-
3610void reactAndroidLoggingHook (
3711 const std::string& message,
3812 android_LogPriority logLevel) {
Original file line number Diff line number Diff line change 55#include < android/log.h>
66#include < string>
77
8- #include < JavaScriptCore/JSContextRef.h>
9-
108namespace facebook {
119namespace 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-
2111void reactAndroidLoggingHook (
2212 const std::string& message,
2313 android_LogPriority logLevel);
You can’t perform that action at this time.
0 commit comments